Skip to content

Two-Factor Authentication (2FA)

Users can enable or disable 2FA from their account settings. The SDK supports TOTP-based authenticator apps like Google Authenticator.

Enabling 2FA

javascript
// 1. Enable 2FA: Returns a QR code URL to scan with Google Authenticator
const setup = await sdk.auth.enable2FA();
console.log(setup.otpauthUrl); // Display this as a QR code in your UI

// 2. Verify 2FA: User enters the 6-digit code from their app to confirm setup
await sdk.auth.verify2FA('123456');

Disabling 2FA

javascript
// User must provide their current 6-digit code to disable
await sdk.auth.disable2FA('123456');

All 2FA methods update the local user state (isTwoFactorEnabled) optimistically and fire onAuthStateChanged so the UI updates immediately.