Skip to content

Commit f8a5b6e

Browse files
psavarmattasArakmar
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 1d0a1db commit f8a5b6e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

server/routes/auth.ts

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

865865
// Create user if one doesn't already exist
866866
if (!user && fullUserInfo.email != null && provider.newUserLogin) {
867+
// Check if a user with this email already exists
868+
const existingUser = await userRepository.findOne({
869+
where: { email: fullUserInfo.email },
870+
});
871+
872+
if (existingUser) {
873+
// If a user with the email exists, throw a 409 Conflict error
874+
return next({
875+
status: 409,
876+
message: 'A user with this email address already exists.',
877+
});
878+
}
879+
867880
logger.info(`Creating user for ${fullUserInfo.email}`, {
868881
ip: req.ip,
869882
email: fullUserInfo.email,

0 commit comments

Comments
 (0)