Two-factor authentication

Add TOTP-based two-factor authentication for enhanced account security.

#Two-factor authentication

EmuView supports TOTP (time-based one-time password) two-factor authentication via Better Auth's TOTP plugin. Users pair an authenticator app like Google Authenticator, Authy, or 1Password with their account.

#How it works

  1. The user enables 2FA from their account settings
  2. EmuView generates a TOTP secret and QR code
  3. The user scans the QR code with their authenticator app
  4. On future sign-ins, the user provides both their password and a 6-digit code

#Enable 2FA (SDK)

// Generate a TOTP secret and QR code
const { qrCode, secret } = await sdk.auth.enableTwoFactor();

// Display the QR code to the user
// User scans it with their authenticator app

// Verify with a code from the app to confirm setup
await sdk.auth.verifyTwoFactor({ code: '123456' });

#Sign in with 2FA (SDK)

const { requiresTwoFactor } = await sdk.auth.signIn({
	email: 'alex@example.com',
	password: 'securePassword123'
});

if (requiresTwoFactor) {
	// Prompt user for their 6-digit code
	await sdk.auth.verifyTwoFactor({ code: '123456' });
}

#Disable 2FA (SDK)

await sdk.auth.disableTwoFactor();

#What you learned

  • 2FA uses TOTP — compatible with Google Authenticator, Authy, 1Password
  • Enable with sdk.auth.enableTwoFactor() and verify with sdk.auth.verifyTwoFactor()
  • Sign-in returns requiresTwoFactor: true when 2FA is active

#Next steps