Skip to content

Commit

Permalink
fix: Support all mfa auth methods (#1030)
Browse files Browse the repository at this point in the history
* fix: support all mfa auth methods

* fix: add unknown mfa type

* style: use orElse instead of firstWhereOrNull

* style: remove import
  • Loading branch information
Vinzent03 authored Sep 20, 2024
1 parent 588b500 commit 773b7de
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/gotrue/lib/src/types/mfa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,25 @@ class AuthMFAGetAuthenticatorAssuranceLevelResponse {
});
}

enum AMRMethod { password, otp, oauth, totp, magiclink }
enum AMRMethod {
password('password'),
otp('otp'),
oauth('oauth'),
totp('totp'),
magiclink('magiclink'),
recovery('recovery'),
invite('invite'),
ssoSaml('sso/saml'),
emailSignUp('email/signup'),
emailChange('email_change'),
tokenRefresh('token_refresh'),
anonymous('anonymous'),
mfaPhone('mfa/phone'),
unknown('unknown');

final String code;
const AMRMethod(this.code);
}

/// An authentication method reference (AMR) entry.
///
Expand All @@ -278,7 +296,8 @@ class AMREntry {
factory AMREntry.fromJson(Map<String, dynamic> json) {
return AMREntry(
method: AMRMethod.values.firstWhere(
(e) => e.name == json['method'],
(e) => e.code == json['method'],
orElse: () => AMRMethod.unknown,
),
timestamp: DateTime.fromMillisecondsSinceEpoch(json['timestamp'] * 1000),
);
Expand Down

0 comments on commit 773b7de

Please sign in to comment.