RegisterLogin
DocsPricing
RegisterLogin
  • Getting Started
  • Introduction
  • Quick Start
  • SDKs
  • React
  • TypeScript
  • Next.js
  • Express
  • NestJS
  • Python
  • API Reference
  • Support and Resources
  • FAQ
  • Contact

useMfa()

Hook for managing multi-factor authentication (MFA) methods. Supports TOTP, Email OTP, and WebAuthn.


Overview

The useMfa() hook provides methods for fetching MFA methods, registering new methods (TOTP, Email OTP, WebAuthn), confirming method registration, removing methods, and setting primary methods. Requires the user to be authenticated.


Basic Usage

'use client';
import { useMfa, useAuth } from 'authsafe-nextjs';

export default function MfaSettings() {
  const { isAuthenticated } = useAuth();
  const { methods, fetchMethods, registerMethod } = useMfa();

  if (!isAuthenticated) return null;

  return (
    <div>
      <h2>MFA Methods</h2>
      {methods.map(method => (
        <p key={method.id}>{method.type}</p>
      ))}
      <button onClick={() => registerMethod('totp')}>Add TOTP</button>
    </div>
  );
}

Best Practices
  • Always check isAuthenticated before showing MFA settings
  • Use fetchMethods() to refresh the list after adding/removing methods
  • Support multiple MFA types for better security flexibility

AuthSafe

Product

HighlightFeatureIntegrationPricingFAQ

Company

AboutBlogContact

Developer

DashboardDocumentation

Legal

Terms & ConditionsPrivacyComplianceShippingCancellationAI

© 2026 AuthSafe. All rights reserved.

We value your privacy

This website uses cookies for anonymous analytics to help us improve your experience. No personal information is stored or shared. You can allow or reject analytics tracking at any time. See our Privacy Policy.

We use cookies for anonymous analytics. No personal info is stored. See our Privacy Policy.