Skip to content

Commit

Permalink
fix(gotrue): remove OtpType deprecation and add assertion to check ty…
Browse files Browse the repository at this point in the history
…pe for resend method (#567)

* remove otp type deprecation

* Update packages/gotrue/lib/src/gotrue_client.dart

Co-authored-by: Vinzent <vinzent03@proton.me>

* Update packages/gotrue/lib/src/gotrue_client.dart

---------

Co-authored-by: Vinzent <vinzent03@proton.me>
  • Loading branch information
dshukertjr and Vinzent03 committed Jul 25, 2023
1 parent 7fbd94c commit d4509de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 0 additions & 2 deletions packages/gotrue/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ extension GenerateLinkTypeExtended on GenerateLinkType {
enum OtpType {
sms,
phoneChange,
@Deprecated('Use OtpType.email instead')
signup,
invite,
@Deprecated('Use OtpType.email instead')
magiclink,
recovery,
emailChange,
Expand Down
14 changes: 12 additions & 2 deletions packages/gotrue/lib/src/gotrue_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,11 @@ class GoTrueClient {
);
}

///Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.
/// Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.
///
///Use [EmailResendParams] or [PhoneResendParams] to specify the type of resend.
/// For [type] of [OtpType.signup] or [OtpType.emailChange] [email] must be
/// provided, and for [type] or [OtpType.sms] or [OtpType.phoneChange],
/// [phone] must be provided
Future<ResendResponse> resend({
String? email,
String? phone,
Expand All @@ -538,6 +540,14 @@ class GoTrueClient {
}) async {
assert((email != null && phone == null) || (email == null && phone != null),
'`email` or `phone` needs to be specified.');
if (email != null) {
assert([OtpType.signup, OtpType.emailChange].contains(type),
'email must be provided for type ${type.name}');
}
if (phone != null) {
assert([OtpType.sms, OtpType.phoneChange].contains(type),
'phone must be provided for type ${type.name}');
}

if (type != OtpType.emailChange && type != OtpType.phoneChange) {
_removeSession();
Expand Down

0 comments on commit d4509de

Please sign in to comment.