mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 10:22:55 +08:00
fix(server): redirect logic in earlyAccessPreview (#4091)
This commit is contained in:
@@ -15,6 +15,7 @@ import Google from 'next-auth/providers/google';
|
|||||||
import { Config } from '../../config';
|
import { Config } from '../../config';
|
||||||
import { PrismaService } from '../../prisma';
|
import { PrismaService } from '../../prisma';
|
||||||
import { NewFeaturesKind } from '../users/types';
|
import { NewFeaturesKind } from '../users/types';
|
||||||
|
import { isStaff } from '../users/utils';
|
||||||
import { MailService } from './mailer';
|
import { MailService } from './mailer';
|
||||||
import { getUtcTimestamp, UserClaim } from './service';
|
import { getUtcTimestamp, UserClaim } from './service';
|
||||||
|
|
||||||
@@ -255,6 +256,9 @@ export const NextAuthOptionsProvider: FactoryProvider<NextAuthOptions> = {
|
|||||||
}
|
}
|
||||||
const email = profile?.email ?? user.email;
|
const email = profile?.email ?? user.email;
|
||||||
if (email) {
|
if (email) {
|
||||||
|
if (isStaff(email)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return prisma.newFeaturesWaitingList
|
return prisma.newFeaturesWaitingList
|
||||||
.findUnique({
|
.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -127,11 +127,15 @@ export class NextAuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (redirect?.endsWith('api/auth/error?error=AccessDenied')) {
|
if (redirect?.endsWith('api/auth/error?error=AccessDenied')) {
|
||||||
res.status(403);
|
if (!req.headers?.referer) {
|
||||||
res.json({
|
res.redirect('https://community.affine.pro/c/insider-general/');
|
||||||
url: 'https://community.affine.pro/c/insider-general/',
|
} else {
|
||||||
error: `You don't have early access permission`,
|
res.status(403);
|
||||||
});
|
res.json({
|
||||||
|
url: 'https://community.affine.pro/c/insider-general/',
|
||||||
|
error: `You don't have early access permission`,
|
||||||
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import type { FileUpload } from '../../types';
|
|||||||
import { Auth, CurrentUser, Public } from '../auth/guard';
|
import { Auth, CurrentUser, Public } from '../auth/guard';
|
||||||
import { StorageService } from '../storage/storage.service';
|
import { StorageService } from '../storage/storage.service';
|
||||||
import { NewFeaturesKind } from './types';
|
import { NewFeaturesKind } from './types';
|
||||||
|
import { isStaff } from './utils';
|
||||||
|
|
||||||
registerEnumType(NewFeaturesKind, {
|
registerEnumType(NewFeaturesKind, {
|
||||||
name: 'NewFeaturesKind',
|
name: 'NewFeaturesKind',
|
||||||
@@ -116,7 +117,7 @@ export class UserResolver {
|
|||||||
})
|
})
|
||||||
@Public()
|
@Public()
|
||||||
async user(@Args('email') email: string) {
|
async user(@Args('email') email: string) {
|
||||||
if (this.config.featureFlags.earlyAccessPreview) {
|
if (this.config.featureFlags.earlyAccessPreview && !isStaff(email)) {
|
||||||
const hasEarlyAccess = await this.prisma.newFeaturesWaitingList
|
const hasEarlyAccess = await this.prisma.newFeaturesWaitingList
|
||||||
.findUnique({
|
.findUnique({
|
||||||
where: { email, type: NewFeaturesKind.EarlyAccess },
|
where: { email, type: NewFeaturesKind.EarlyAccess },
|
||||||
|
|||||||
3
apps/server/src/modules/users/utils.ts
Normal file
3
apps/server/src/modules/users/utils.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function isStaff(email: string) {
|
||||||
|
return email.endsWith('@toeverything.info');
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user