enroll method

Future<AuthMFAEnrollResponse> enroll({
  1. FactorType factorType = FactorType.totp,
  2. String? issuer,
  3. String? friendlyName,
})

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.

Upon verifying a factor, all other sessions are logged out and the current session's authenticator level is promoted to aal2.

factorType : Type of factor being enrolled.

issuer : Domain which the user is enrolled with.

friendlyName : Human readable name assigned to the factor.

Implementation

Future<AuthMFAEnrollResponse> enroll({
  FactorType factorType = FactorType.totp,
  String? issuer,
  String? friendlyName,
}) async {
  final session = _client.currentSession;
  final data = await _fetch.request(
    '${_client._url}/factors',
    RequestMethodType.post,
    options: GotrueRequestOptions(
      headers: _client._headers,
      body: {
        'friendly_name': friendlyName,
        'factor_type': factorType.name,
        'issuer': issuer,
      },
      jwt: session?.accessToken,
    ),
  );

  data['totp']['qr_code'] =
      'data:image/svg+xml;utf-8,${data['totp']['qr_code']}';

  final response = AuthMFAEnrollResponse.fromJson(data);
  return response;
}