From e285a4e634789f129860e11063f91b3edc90cee5 Mon Sep 17 00:00:00 2001 From: Mathis HERRIOT <197931332+0x485254@users.noreply.github.com> Date: Tue, 20 Jan 2026 09:44:12 +0100 Subject: [PATCH] feat(auth): add detailed logging for login and 2FA operations Introduce warnings for failed login attempts and invalid 2FA tokens. Add logs for successful logins and 2FA requirements to improve authentication traceability. --- backend/src/auth/auth.service.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/src/auth/auth.service.ts b/backend/src/auth/auth.service.ts index 2133afb..e5adba1 100644 --- a/backend/src/auth/auth.service.ts +++ b/backend/src/auth/auth.service.ts @@ -110,6 +110,7 @@ export class AuthService { const user = await this.usersService.findByEmailHash(emailHash); if (!user) { + this.logger.warn(`Login failed: user not found for email hash`); throw new UnauthorizedException("Invalid credentials"); } @@ -119,10 +120,12 @@ export class AuthService { ); if (!isPasswordValid) { + this.logger.warn(`Login failed: invalid password for user ${user.uuid}`); throw new UnauthorizedException("Invalid credentials"); } if (user.isTwoFactorEnabled) { + this.logger.log(`2FA required for user ${user.uuid}`); return { message: "2FA required", requires2FA: true, @@ -141,6 +144,7 @@ export class AuthService { ip, ); + this.logger.log(`User ${user.uuid} logged in successfully`); return { message: "User logged in successfully", access_token: accessToken, @@ -165,6 +169,7 @@ export class AuthService { const isValid = authenticator.verify({ token, secret }); if (!isValid) { + this.logger.warn(`2FA verification failed for user ${userId}: invalid token`); throw new UnauthorizedException("Invalid 2FA token"); } @@ -179,6 +184,7 @@ export class AuthService { ip, ); + this.logger.log(`User ${userId} logged in successfully via 2FA`); return { message: "User logged in successfully (2FA)", access_token: accessToken,