From b240a19156caf6c60d796a5847761fa5631223c7 Mon Sep 17 00:00:00 2001 From: Andres Pinto Date: Mon, 13 Jan 2025 11:40:45 -0400 Subject: [PATCH] fix: lower case emails on auth endpoints --- src/modules/auth/auth.controller.ts | 4 +++- src/modules/user/user.usecase.ts | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index 3daf939b..38cc9fa4 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -60,7 +60,9 @@ export class AuthController { @ApiOkResponse({ description: 'Retrieve details' }) @Public() async login(@Body() body: LoginDto) { - const user = await this.userUseCases.findByEmail(body.email); + const email = body.email.toLowerCase(); + + const user = await this.userUseCases.findByEmail(email); if (!user) { throw new UnauthorizedException('Wrong login credentials'); diff --git a/src/modules/user/user.usecase.ts b/src/modules/user/user.usecase.ts index 7e326be7..da34e479 100644 --- a/src/modules/user/user.usecase.ts +++ b/src/modules/user/user.usecase.ts @@ -356,7 +356,8 @@ export class UserUseCases { } async createUser(newUser: NewUser) { - const { email, password, salt } = newUser; + const { email: rawEmail, password, salt } = newUser; + const email = rawEmail.toLowerCase(); const maybeExistentUser = await this.userRepository.findByUsername(email); const userAlreadyExists = !!maybeExistentUser; @@ -1197,7 +1198,7 @@ export class UserUseCases { async loginAccess(loginAccessDto: LoginAccessDto) { const MAX_LOGIN_FAIL_ATTEMPTS = 10; - const userData = await this.findByEmail(loginAccessDto.email); + const userData = await this.findByEmail(loginAccessDto.email.toLowerCase()); if (!userData) { Logger.debug( @@ -1263,7 +1264,7 @@ export class UserUseCases { } const user = { - email: loginAccessDto.email, + email: userData.email, userId: userData.userId, mnemonic: userData.mnemonic.toString(), root_folder_id: userData.rootFolderId,