From f97bb08c5cc9175c35717ff8c13d81dfbfdd9ba4 Mon Sep 17 00:00:00 2001 From: Abdalhamid Alhamad Date: Thu, 5 Dec 2024 11:42:56 +0300 Subject: [PATCH] fix: handle duplicate emails --- src/auth/services/auth.service.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/auth/services/auth.service.ts b/src/auth/services/auth.service.ts index 18d13f1..1e261e6 100644 --- a/src/auth/services/auth.service.ts +++ b/src/auth/services/auth.service.ts @@ -73,6 +73,12 @@ export class AuthService { throw new BadRequestException('USERS.EMAIL_ALREADY_SET'); } + const existingUser = await this.userService.findUser({ email }); + + if (existingUser) { + throw new BadRequestException('USERS.EMAIL_ALREADY_TAKEN'); + } + return this.userService.setEmail(userId, email); }