fix: Incorrect error message when attempting to join team without error message
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import invariant from "invariant";
|
import invariant from "invariant";
|
||||||
import WelcomeEmail from "@server/emails/templates/WelcomeEmail";
|
import WelcomeEmail from "@server/emails/templates/WelcomeEmail";
|
||||||
import {
|
import {
|
||||||
AuthenticationError,
|
|
||||||
InvalidAuthenticationError,
|
InvalidAuthenticationError,
|
||||||
AuthenticationProviderDisabledError,
|
AuthenticationProviderDisabledError,
|
||||||
} from "@server/errors";
|
} from "@server/errors";
|
||||||
@@ -127,62 +126,59 @@ async function accountProvisioner({
|
|||||||
throw AuthenticationProviderDisabledError();
|
throw AuthenticationProviderDisabledError();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
result = await userProvisioner({
|
||||||
const result = await userProvisioner({
|
name: userParams.name,
|
||||||
name: userParams.name,
|
email: userParams.email,
|
||||||
email: userParams.email,
|
isAdmin: isNewTeam || undefined,
|
||||||
isAdmin: isNewTeam || undefined,
|
avatarUrl: userParams.avatarUrl,
|
||||||
avatarUrl: userParams.avatarUrl,
|
teamId: team.id,
|
||||||
teamId: team.id,
|
ip,
|
||||||
ip,
|
authentication: emailMatchOnly
|
||||||
authentication: emailMatchOnly
|
? undefined
|
||||||
? undefined
|
: {
|
||||||
: {
|
authenticationProviderId: authenticationProvider.id,
|
||||||
authenticationProviderId: authenticationProvider.id,
|
...authenticationParams,
|
||||||
...authenticationParams,
|
expiresAt: authenticationParams.expiresIn
|
||||||
expiresAt: authenticationParams.expiresIn
|
? new Date(Date.now() + authenticationParams.expiresIn * 1000)
|
||||||
? new Date(Date.now() + authenticationParams.expiresIn * 1000)
|
: undefined,
|
||||||
: undefined,
|
},
|
||||||
},
|
});
|
||||||
});
|
const { isNewUser, user } = result;
|
||||||
const { isNewUser, user } = result;
|
|
||||||
|
|
||||||
if (isNewUser) {
|
// TODO: Move to processor
|
||||||
await new WelcomeEmail({
|
if (isNewUser) {
|
||||||
to: user.email,
|
await new WelcomeEmail({
|
||||||
teamUrl: team.url,
|
to: user.email,
|
||||||
}).schedule();
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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({
|
export default traceFunction({
|
||||||
|
|||||||
Reference in New Issue
Block a user