From 9fde70b92440d0710e50bc04f897be727d449441 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 20 Dec 2023 18:47:43 -0400 Subject: [PATCH] fix: Incorrect error message when attempting to join team without error message --- server/commands/accountProvisioner.ts | 106 +++++++++++++------------- 1 file changed, 51 insertions(+), 55 deletions(-) diff --git a/server/commands/accountProvisioner.ts b/server/commands/accountProvisioner.ts index b32f598d0..11d00f217 100644 --- a/server/commands/accountProvisioner.ts +++ b/server/commands/accountProvisioner.ts @@ -1,7 +1,6 @@ import invariant from "invariant"; import WelcomeEmail from "@server/emails/templates/WelcomeEmail"; import { - AuthenticationError, InvalidAuthenticationError, AuthenticationProviderDisabledError, } from "@server/errors"; @@ -127,62 +126,59 @@ async function accountProvisioner({ throw AuthenticationProviderDisabledError(); } - try { - const result = await userProvisioner({ - name: userParams.name, - email: userParams.email, - isAdmin: isNewTeam || undefined, - avatarUrl: userParams.avatarUrl, - teamId: team.id, - ip, - authentication: emailMatchOnly - ? undefined - : { - authenticationProviderId: authenticationProvider.id, - ...authenticationParams, - expiresAt: authenticationParams.expiresIn - ? new Date(Date.now() + authenticationParams.expiresIn * 1000) - : undefined, - }, - }); - const { isNewUser, user } = result; + result = await userProvisioner({ + name: userParams.name, + email: userParams.email, + isAdmin: isNewTeam || undefined, + avatarUrl: userParams.avatarUrl, + teamId: team.id, + ip, + authentication: emailMatchOnly + ? undefined + : { + authenticationProviderId: authenticationProvider.id, + ...authenticationParams, + expiresAt: authenticationParams.expiresIn + ? new Date(Date.now() + authenticationParams.expiresIn * 1000) + : undefined, + }, + }); + const { isNewUser, user } = result; - if (isNewUser) { - await new WelcomeEmail({ - to: user.email, - teamUrl: team.url, - }).schedule(); - } - - if (isNewUser || isNewTeam) { - let provision = isNewTeam; - - // accounts for the case where a team is provisioned, but the user creation - // failed. In this case we have a valid previously created team but no - // onboarding collection. - if (!isNewTeam) { - const count = await Collection.count({ - where: { - teamId: team.id, - }, - }); - provision = count === 0; - } - - if (provision) { - await team.provisionFirstCollection(user.id); - } - } - - return { - user, - team, - isNewUser, - isNewTeam, - }; - } catch (err) { - throw AuthenticationError(err.message); + // TODO: Move to processor + if (isNewUser) { + await new WelcomeEmail({ + to: user.email, + teamUrl: team.url, + }).schedule(); } + + if (isNewUser || isNewTeam) { + let provision = isNewTeam; + + // accounts for the case where a team is provisioned, but the user creation + // failed. In this case we have a valid previously created team but no + // onboarding collection. + if (!isNewTeam) { + const count = await Collection.count({ + where: { + teamId: team.id, + }, + }); + provision = count === 0; + } + + if (provision) { + await team.provisionFirstCollection(user.id); + } + } + + return { + user, + team, + isNewUser, + isNewTeam, + }; } export default traceFunction({