Skip to content

Commit

Permalink
fix: lower case emails on auth endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
apsantiso committed Jan 13, 2025
1 parent 9ce91a8 commit b240a19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 4 additions & 3 deletions src/modules/user/user.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b240a19

Please sign in to comment.