Kotlin: Enroll a factor

Enrolls a new factor.

Parameters

Examples

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

val factor = supabase.auth.mfa.enroll(factorType = FactorType.TOTP, friendlyName = "Your friendly Name") \{
      // Optional
      issuer = "example.com"
\}

// 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.
val (id, type, qrCode) = factor.data //qrCode is a svg as a string
val (factorId, factorType, _) = factor
val challenge = supabase.auth.mfa.createChallenge(factor.id)

Enroll a Phone Factor

val factor = supabase.auth.mfa.enroll(factorType = FactorType.Phone, friendlyName = "Your friendly Name") \{
      phone = "+123456789" 
\}

// Use the id to create a challenge and send an SMS with a code to the user.
val (phone) = factor.data
val (factorId, factorType, _) = factor
val challenge = supabase.auth.mfa.createChallenge(factor.id)

Check the local user for verified factors

val verifiedFactors = supabase.auth.mfa.verifiedFactors

Retrieve verified factors

val verifiedFactors = supabase.auth.mfa.retrieveFactorsForCurrentUser()