From ec34572087b8d9acdd03cc05b8bf22f8b6d9a01e Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Tue, 23 May 2023 13:17:58 -0400 Subject: [PATCH] patch invite only --- backend/src/config/index.ts | 2 +- backend/src/controllers/v1/signupController.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index 7d46580a1..f7555248a 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -5,7 +5,7 @@ const client = new InfisicalClient({ }); export const getPort = async () => (await client.getSecret('PORT')).secretValue || 4000; -export const getInviteOnlySignup = async () => (await client.getSecret('INVITE_ONLY_SIGNUP')).secretValue == undefined ? false : (await client.getSecret('INVITE_ONLY_SIGNUP')).secretValue; +export const getInviteOnlySignup = async () => (await client.getSecret('INVITE_ONLY_SIGNUP')).secretValue === 'true' export const getEncryptionKey = async () => (await client.getSecret('ENCRYPTION_KEY')).secretValue; export const getSaltRounds = async () => parseInt((await client.getSecret('SALT_ROUNDS')).secretValue) || 10; export const getJwtAuthLifetime = async () => (await client.getSecret('JWT_AUTH_LIFETIME')).secretValue || '10d'; diff --git a/backend/src/controllers/v1/signupController.ts b/backend/src/controllers/v1/signupController.ts index 193699c15..e5af676b3 100644 --- a/backend/src/controllers/v1/signupController.ts +++ b/backend/src/controllers/v1/signupController.ts @@ -21,14 +21,6 @@ export const beginEmailSignup = async (req: Request, res: Response) => { try { email = req.body.email; - if (await getInviteOnlySignup()) { - // Only one user can create an account without being invited. The rest need to be invited in order to make an account - const userCount = await User.countDocuments({}) - if (userCount != 0) { - throw BadRequestError({ message: "New user sign ups are not allowed at this time. You must be invited to sign up." }) - } - } - const user = await User.findOne({ email }).select('+publicKey'); if (user && user?.publicKey) { // case: user has already completed account @@ -74,6 +66,14 @@ export const verifyEmailSignup = async (req: Request, res: Response) => { }); } + if (await getInviteOnlySignup()) { + // Only one user can create an account without being invited. The rest need to be invited in order to make an account + const userCount = await User.countDocuments({}) + if (userCount != 0) { + throw BadRequestError({ message: "New user sign ups are not allowed at this time. You must be invited to sign up." }) + } + } + // verify email if (await getSmtpConfigured()) { await checkEmailVerification({