fix: Incorrect error message when attempting to join team without error message

This commit is contained in:
Tom Moor
2023-12-20 18:47:43 -04:00
parent 56e6b5211a
commit 9fde70b924

View File

@@ -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({