From 473012f2c05001a85146b0495a751cd3d85cc209 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Thu, 8 Feb 2024 22:16:21 +0530 Subject: [PATCH] fix: organization user shouldn't be asked for payment for a premium username (#13535) Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> --- packages/lib/server/username.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/lib/server/username.ts b/packages/lib/server/username.ts index 0cd23bad78..cc5abc0176 100644 --- a/packages/lib/server/username.ts +++ b/packages/lib/server/username.ts @@ -181,12 +181,11 @@ const usernameCheckForSignup = async ({ const user = await prisma.user.findFirst({ where: { email, - // Simply remove it when we drop organizationId column - organizationId: null, }, select: { id: true, username: true, + organizationId: true, }, }); @@ -206,13 +205,15 @@ const usernameCheckForSignup = async ({ // When we invite an email, that doesn't match the orgAutoAcceptEmail, we create a user with organizationId=null. // The only way to differentiate b/w 'a new email that was invited to an Org' and 'a user that was created using regular signup' is to check if the user is a member of an org. + // If username is in global namespace if (!userIsAMemberOfAnOrg) { response.available = false; + // There are no premium users outside an organization only + response.premium = await isPremiumUserName(username); } - } - - if (await isPremiumUserName(username)) { - response.premium = true; + } else { + // If user isn't found, it's a new signup and that can't be of an organization + response.premium = await isPremiumUserName(username); } // get list of similar usernames in the db