JavaScript: Enroll a factor

Starts the enrollment process for a new Multi-Factor Authentication (MFA) factor. This method creates a new unverified factor. To verify a factor, present the QR code or secret to the user and ask them to add it to their authenticator app. The user has to enter the code from their authenticator app to verify it.

<Image src=\{data.totp.qr_code\} alt=\{data.totp.uri\} layout="fill"></Image>

Parameters

Examples

Enroll a time-based, one-time password (TOTP) factor

const \{ data, error \} = await supabase.auth.mfa.enroll(\{
  factorType: 'totp',
  friendlyName: 'your_friendly_name'
\})

// Use the id to create a challenge.
// The challenge can be verified by entering the code generated from the authenticator app.
// The code will be generated upon scanning the qr_code or entering the secret into the authenticator app.
const \{ id, type, totp: \{ qr_code, secret, uri \}, friendly_name \} = data
const challenge = await supabase.auth.mfa.challenge(\{ factorId: id \});

Enroll a Phone Factor

const \{ data, error \} = await supabase.auth.mfa.enroll(\{
  factorType: 'phone',
  friendlyName: 'your_friendly_name',
  phone: '+12345678',
\})

// Use the id to create a challenge and send an SMS with a code to the user.
const \{ id, type, friendly_name, phone \} = data

const challenge = await supabase.auth.mfa.challenge(\{ factorId: id \});