Skip to content

Fixed Passport handles expected errors as exceptions #3050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions server/config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ passport.use(
User.findOne({ github: profile.id }, (findByGithubErr, existingUser) => {
if (existingUser) {
if (req.user && req.user.email !== existingUser.email) {
done(
new Error('GitHub account is already linked to another account.')
);
done(null, false, {
msg: 'GitHub account is already linked to another account.'
});
return;
} else if (existingUser.banned) {
done(new Error(accountSuspensionMessage));
done(null, false, { msg: accountSuspensionMessage });
return;
}
done(null, existingUser);
Expand Down Expand Up @@ -159,7 +159,7 @@ passport.use(
[existingEmailUser] = existingEmailUsers;
}
if (existingEmailUser.banned) {
done(new Error(accountSuspensionMessage));
done(null, false, { msg: accountSuspensionMessage });
return;
}
existingEmailUser.email = existingEmailUser.email || primaryEmail;
Expand Down Expand Up @@ -218,14 +218,12 @@ passport.use(
(findByGoogleErr, existingUser) => {
if (existingUser) {
if (req.user && req.user.email !== existingUser.email) {
done(
new Error(
'Google account is already linked to another account.'
)
);
done(null, false, {
msg: 'Google account is already linked to another account.'
});
return;
} else if (existingUser.banned) {
done(new Error(accountSuspensionMessage));
done(null, false, { msg: accountSuspensionMessage });
return;
}
done(null, existingUser);
Expand Down Expand Up @@ -256,7 +254,7 @@ passport.use(
// then, append a random friendly word?
if (existingEmailUser) {
if (existingEmailUser.banned) {
done(new Error(accountSuspensionMessage));
done(null, false, { msg: accountSuspensionMessage });
return;
}
existingEmailUser.email =
Expand Down