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.
totp
or phone
as the factorType
and use the returned id
to create a challenge.mfa.challenge()
.mfa.verify()
.mfa.challengeAndVerify()
.totp
secret in Next.js, you can do the following:<Image src=\{data.totp.qr_code\} alt=\{data.totp.uri\} layout="fill"></Image>
challenge
and verify
steps are separated when using Phone factors as the user will need time to receive and input the code obtained from the SMS in challenge.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 \});
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 \});