JavaScript: generate

Generates the user's set of recovery codes. The plaintext codes are returned exactly once in the response and cannot be retrieved again, so show them to the user and ask them to store the codes safely.

Requires auth.experimental.recoveryCodes: true.

Parameters

Examples

Generate recovery codes

const supabase = createClient(supabaseUrl, supabaseKey, {
  auth: { experimental: { recoveryCodes: true } },
})

const { data, error } = await supabase.auth.mfa.recoveryCodes.generate({
  friendlyName: 'Backup codes',
})

// Show the codes once, for example grouped in blocks of four characters
const formatted = data.codes.map((code) => code.match(/.{1,4}/g).join('-'))