Skip to content

Commit c5e66b1

Browse files
psavarmattasvoc0der
authored andcommitted
fix(auth): prevent duplicate user creation on OIDC login
Adds a check to ensure a user with the same email address does not already exist before creating a new user during an OIDC callback. If a duplicate email is found, the process is aborted with a 409 Conflict error. Addresses seerr-team#1505 (comment)
1 parent 6903485 commit c5e66b1

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

server/routes/auth.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,19 @@ authRoutes.get('/oidc/callback/:slug', async (req, res, next) => {
939939

940940
// Create user if one doesn't already exist
941941
if (!user && fullUserInfo.email != null && provider.newUserLogin) {
942+
// Check if a user with this email already exists
943+
const existingUser = await userRepository.findOne({
944+
where: { email: fullUserInfo.email },
945+
});
946+
947+
if (existingUser) {
948+
// If a user with the email exists, throw a 409 Conflict error
949+
return next({
950+
status: 409,
951+
message: 'A user with this email address already exists.',
952+
});
953+
}
954+
942955
logger.info(`Creating user for ${fullUserInfo.email}`, {
943956
ip: req.ip,
944957
email: fullUserInfo.email,

0 commit comments

Comments
 (0)