-
Notifications
You must be signed in to change notification settings - Fork 134
Open
Labels
good first issueGood for newcomersGood for newcomers
Description
Location: backend/src/auth/providers/manage-totp.provider.ts
Description
Members need two additional management capabilities after enabling 2FA: the ability to check their current 2FA status (whether it is enabled and how many backup codes remain) and the ability to disable it entirely by confirming their password. Disabling 2FA must require password confirmation to prevent an attacker with a stolen session from silently removing the second factor.
Acceptance Criteria
- A
ManageTotpProviderclass is created atbackend/src/auth/providers/manage-totp.provider.ts - A
get2faStatus(userId: string)method:- Loads the user — throws
NotFoundExceptionif not found - Returns
{ enabled: boolean, backupCodesRemaining: number }wherebackupCodesRemainingisuser.totpBackupCodes?.length ?? 0
- Loads the user — throws
- A
disable2fa(userId: string, password: string)method:- Loads the user — throws
NotFoundExceptionif not found - Throws
BadRequestExceptioniftwoFactorEnabledis alreadyfalse - Verifies the provided password against
user.passwordusing the existinghashingProvider.comparePassword()(or equivalent) — throwsUnauthorizedExceptionwith"Invalid password"if it does not match - Sets
user.twoFactorEnabled = false,user.totpSecret = null,user.totpBackupCodes = nulland saves - Returns
{ message: "Two-factor authentication has been disabled" }
- Loads the user — throws
-
ManageTotpProvideris registered inbackend/src/auth/auth.module.ts -
npx tsc --noEmitpasses with no errors
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers