Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gotrue): remove OtpType deprecation and add assertion to check type for resend method #567

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading