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

@@ -63,9 +63,9 @@ const createHelmCommand = ({ isDryRun }) => {
`--set-json sync.service.annotations=\"{ \\"cloud.google.com/neg\\": \\"{\\\\\\"ingress\\\\\\": true}\\" }\"`,
]
: [];
const webReplicaCount = isProduction ? 3 : isBeta ? 2 : 1;
const graphqlReplicaCount = isProduction ? 3 : isBeta ? 2 : 1;
const syncReplicaCount = isProduction ? 6 : isBeta ? 3 : 1;
const webReplicaCount = isProduction ? 3 : isBeta ? 2 : 2;
const graphqlReplicaCount = isProduction ? 3 : isBeta ? 2 : 2;
const syncReplicaCount = isProduction ? 6 : isBeta ? 3 : 2;
const namespace = isProduction ? 'production' : isBeta ? 'beta' : 'dev';
const deployCommand = [
`helm upgrade --install affine .github/helm/affine`,

View File

@@ -21,6 +21,8 @@ function validateEmail(email: string) {
return emailRegex.test(email);
}
const INTERNAL_BETA_URL = `https://community.affine.pro/c/insider-general/`;
function handleSendEmailError(
res: SignInResponse | undefined,
pushNotification: (notification: Notification) => void
@@ -32,6 +34,13 @@ function handleSendEmailError(
type: 'error',
});
}
if (res?.status === 403 && res?.url === INTERNAL_BETA_URL) {
pushNotification({
title: 'Sign up error',
message: `You don't have early access permission\nVisit ${INTERNAL_BETA_URL} for more information`,
type: 'error',
});
}
}
export const SignIn: FC<AuthPanelProps> = ({

View File

@@ -74,6 +74,7 @@
"@napi-rs/image": "^1.6.1",
"@nestjs/testing": "^10.2.1",
"@types/cookie-parser": "^1.4.3",
"@types/engine.io": "^3.1.7",
"@types/express": "^4.17.17",
"@types/lodash-es": "^4.17.8",
"@types/node": "^18.17.11",

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;

View File

@@ -22,6 +22,7 @@ function getIoManager(): Manager {
}
ioManager = new Manager(runtimeConfig.serverUrlPrefix + '/', {
autoConnect: false,
transports: ['websocket'],
});
return ioManager;
}

View File

@@ -689,6 +689,7 @@ __metadata:
"@prisma/instrumentation": ^5.0.0
"@socket.io/redis-adapter": ^8.2.1
"@types/cookie-parser": ^1.4.3
"@types/engine.io": ^3.1.7
"@types/express": ^4.17.17
"@types/lodash-es": ^4.17.8
"@types/node": ^18.17.11
@@ -12963,6 +12964,15 @@ __metadata:
languageName: node
linkType: hard
"@types/engine.io@npm:^3.1.7":
version: 3.1.7
resolution: "@types/engine.io@npm:3.1.7"
dependencies:
"@types/node": "*"
checksum: 62b129eac3fca625cfae4591d4fab56872c44c1f7bb625af2f9e6c1bb28f8210276026e1007dc2da433ee5943972534078402515168135cc155a18c41dfec6a2
languageName: node
linkType: hard
"@types/escodegen@npm:^0.0.6":
version: 0.0.6
resolution: "@types/escodegen@npm:0.0.6"