fix(server): signup/signin logic (#4008)

This commit is contained in:
LongYinan
2023-08-29 19:22:56 +08:00
committed by GitHub
parent a046cdafa3
commit 54574e5cc3
8 changed files with 39 additions and 9 deletions

View File

@@ -266,15 +266,16 @@ export const NextAuthOptionsProvider: FactoryProvider<NextAuthOptions> = {
}
return session;
},
signIn: async ({ profile }) => {
signIn: async ({ profile, user }) => {
if (!config.affine.beta || !config.node.prod) {
return true;
}
if (profile?.email) {
return await prisma.newFeaturesWaitingList
const email = profile?.email ?? user.email;
if (email) {
return prisma.newFeaturesWaitingList
.findUnique({
where: {
email: profile.email,
email,
type: NewFeaturesKind.EarlyAccess,
},
})

View File

@@ -3,6 +3,7 @@ import {
BadRequestException,
Controller,
Inject,
Logger,
Next,
NotFoundException,
Query,
@@ -27,6 +28,8 @@ const BASE_URL = '/api/auth/';
export class NextAuthController {
private readonly callbackSession;
private readonly logger = new Logger('NextAuthController');
constructor(
readonly config: Config,
readonly prisma: PrismaService,
@@ -120,7 +123,11 @@ export class NextAuthController {
}
if (redirect?.endsWith('api/auth/error?error=AccessDenied')) {
res.redirect('https://community.affine.pro/c/insider-general/');
res.status(403);
res.json({
url: 'https://community.affine.pro/c/insider-general/',
error: `You don't have early access permission`,
});
return;
}
@@ -129,7 +136,7 @@ export class NextAuthController {
}
if (redirect) {
console.log(providerId, action, req.headers);
this.logger.debug(providerId, action, req.headers);
if (providerId === 'credentials') {
res.send(JSON.stringify({ ok: true, url: redirect }));
} else if (

View File

@@ -16,6 +16,7 @@ import { DocManager } from '../../doc';
@WebSocketGateway({
cors: process.env.NODE_ENV !== 'production',
transports: ['websocket'],
})
export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
private connectionCount = 0;