From 93e54d28899f8b0ea87bf86856bca2ed80987cf8 Mon Sep 17 00:00:00 2001 From: omargamal10 Date: Mon, 15 Dec 2025 22:50:59 +0200 Subject: [PATCH] fix: add another email check before final user creation --- src/auth/auth.service.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 3a019ea5..33c2da19 100755 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -198,6 +198,17 @@ export class AuthService { ipAddress: ipAddress || 'unknown', userAgent: deviceType, }; + // check if email exists (maybe user registered in the meanwhile from another device) + const existingUser = await this.usersService.findByEmail(registrationData.email); + if (existingUser) { + throw new HttpException( + { + message: AUTH_ERROR_MESSAGES.EMAIL_REGISTERED, + code: AUTH_ERROR_CODES.EMAIL_REGISTERED, + }, + HttpStatus.BAD_REQUEST, + ); + } const userId = await this.createUserAndSessionAndToken(userData, newSession, refreshToken); const accessToken = await this.jwtService.signAsync({ id: userId.toString() });