JavaScript: Enroll a factor | Supabase Docs (original) (raw)
- Introduction
- Installing
- Initializing
- TypeScript support
- Database
- Fetch data
- Insert data
- Update data
- Upsert data
- Delete data
- Call a Postgres function
- Using filters
- Column is equal to a value
- Column is not equal to a value
- Column is greater than a value
- Column is greater than or equal to a value
- Column is less than a value
- Column is less than or equal to a value
- Column matches a pattern
- Column matches a case-insensitive pattern
- Column is a value
- Column is in an array
- Column contains every element in a value
- Contained by value
- Greater than a range
- Greater than or equal to a range
- Less than a range
- Less than or equal to a range
- Mutually exclusive to a range
- With a common element
- Match a string
- Match an associated value
- Don't match the filter
- Match at least one filter
- Match the filter
- Using modifiers
- Return data after inserting
- Order the results
- Limit the number of rows returned
- Limit the query to a range
- Set an abort signal
- Retrieve one row of data
- Retrieve zero or one row of data
- Retrieve as a CSV
- Override type of successful response
- Partially override or replace type of successful response
- Using explain
- Auth
- Overview
- Create a new user
- Listen to auth events
- Create an anonymous user
- Sign in a user
- Sign in with ID Token
- Sign in a user through OTP
- Sign in a user through OAuth
- Sign in a user through SSO
- Sign out a user
- Send a password reset request
- Verify and log in through OTP
- Retrieve a session
- Retrieve a new session
- Retrieve a user
- Update a user
- Retrieve identities linked to a user
- Link an identity to a user
- Unlink an identity from a user
- Send a password reauthentication nonce
- Resend an OTP
- Set the session data
- Exchange an auth code for a session
- Start auto-refresh session (non-browser)
- Stop auto-refresh session (non-browser)
- Auth MFA
- Enroll a factor
- Create a challenge
- Verify a challenge
- Create and verify a challenge
- Unenroll a factor
- Get Authenticator Assurance Level
- Auth Admin
- Retrieve a user
- List all users
- Create a user
- Delete a user
- Send an email invite link
- Generate an email link
- Update a user
- Delete a factor for a user
- Edge Functions
- Invokes a Supabase Edge Function.
- Realtime
- Subscribe to channel
- Unsubscribe from a channel
- Unsubscribe from all channels
- Retrieve all channels
- Broadcast a message
- Storage
- Create a bucket
- Retrieve a bucket
- List all buckets
- Update a bucket
- Delete a bucket
- Empty a bucket
- Upload a file
- Download a file
- List all files in a bucket
- Replace an existing file
- Move an existing file
- Copy an existing file
- Delete files in a bucket
- Create a signed URL
- Create signed URLs
- Create signed upload URL
- Upload to a signed URL
- Retrieve public URL
- Misc
- Release Notes
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.
- Use
totp
orphone
as thefactorType
and use the returnedid
to create a challenge. - To create a challenge, see mfa.challenge().
- To verify a challenge, see mfa.verify().
- To create and verify a TOTP challenge in a single step, see mfa.challengeAndVerify().
- To generate a QR code for the
totp
secret in Next.js, you can do the following:
<Image src={data.totp.qr_code} alt={data.totp.uri} layout="fill"></Image>
- The
challenge
andverify
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.
Parameters
params
(Required)
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 });