For AI agents: the documentation index is at llms.txt. Guide pages have a markdown version at the same path with .md appended, before any query string or fragment.

Swift: Enroll a factor

Examples

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

let enrollment = try await supabase.auth.mfa.enrollTOTP(
  issuer: "optional issuer",
  friendlyName: "optional 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 qrCode or entering the secret into the authenticator app.
let id = enrollment.id
let qrCode = enrollment.qrCode
let secret = enrollment.secret
let uri = enrollment.uri

Enroll a phone factor

let enrollment = try await supabase.auth.mfa.enrollPhone(
  "+15555550100",
  friendlyName: "Work phone"
)

// Send a code to the phone, then verify it with mfa.verify().
let challenge = try await supabase.auth.mfa.challenge(factorID: enrollment.id)

Enroll a WebAuthn (passkey) factor (experimental)

// @_spi(Experimental) import Supabase
// enrollWebAuthn runs the full ceremony: enroll, challenge, show the passkey sheet, verify.
// A nil anchor uses the app's key window.
let session = try await supabase.auth.mfa.enrollWebAuthn(
  friendlyName: "My passkey"
)