Skip to content

Commit 0a37c2d

Browse files
committed
fix json parsing
1 parent 8ca8187 commit 0a37c2d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/gotrue/lib/src/types/mfa.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AuthMFAEnrollResponse {
2929
? TOTPEnrollment.fromJson(json['totp'])
3030
: null,
3131
phone: type == FactorType.phone && json['phone'] != null
32-
? PhoneEnrollment.fromJson(json['phone'])
32+
? PhoneEnrollment._fromJsonValue(json['phone'])
3333
: null,
3434
);
3535
}
@@ -77,6 +77,19 @@ class PhoneEnrollment {
7777
phone: json['phone'],
7878
);
7979
}
80+
81+
factory PhoneEnrollment._fromJsonValue(dynamic value) {
82+
if (value is String) {
83+
// Server returns phone number as a string directly
84+
return PhoneEnrollment(phone: value);
85+
} else if (value is Map<String, dynamic>) {
86+
// Server returns phone data as an object
87+
return PhoneEnrollment.fromJson(value);
88+
} else {
89+
throw ArgumentError(
90+
'Invalid phone enrollment data type: ${value.runtimeType}');
91+
}
92+
}
8093
}
8194

8295
class AuthMFAChallengeResponse {

0 commit comments

Comments
 (0)