Authentication & MFA
Login checks password, account status, email verification, and optional two-factor authentication.
Login
The login method:
- Finds the account by email
- Verifies the password hash
- Checks that the email is verified
- Checks that the account status is
Normal(not banned, locked, etc.) - If 2FA is enabled and the user has verified methods, throws
SecondFactorRequiredError - Otherwise, creates a session and optionally sets a remember-me token
Two-Factor Challenge
When SecondFactorRequiredError is thrown, the user is not logged in yet. The error includes availableMethods describing which mechanisms are available (TOTP, email, SMS). The session holds an awaitingTwoFactor state with an expiry.
Return the available methods to the client so it can show the appropriate UI. Do not return raw OTP codes to the client - send them via your email/SMS service.
Completing 2FA
After verification succeeds, call completeTwoFactorLogin() to finish the login:
Verifiers: verify.totp(), verify.email(), verify.sms(), verify.backupCode(), verify.otp() (tries email and SMS automatically).
See the MFA Patterns guide for full implementation examples including OTP delivery.
Remember Me
Login with remember: true creates a persistent token in {prefix}remembers and sets an httpOnly cookie. On future requests, the middleware auto-restores the session from the cookie. Configure rememberDuration and rememberCookieName in AuthConfig.
Logout
logout()clears the current session and remember tokenlogoutEverywhere()clears all sessions and remember tokenslogoutEverywhereElse()keeps the current session, clears everything else