Skip to content

Commit

Permalink
feat(gotrue): add WhatsApp support for OTP login (#613)
Browse files Browse the repository at this point in the history
* feat: add otp channel to support whatapp otp

* update comment

* feat: add channel paramter to sign up

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

Co-authored-by: Bruno D'Luka <45696119+bdlukaa@users.noreply.github.com>

* give channel default values

---------

Co-authored-by: Bruno D'Luka <45696119+bdlukaa@users.noreply.github.com>
  • Loading branch information
dshukertjr and bdlukaa authored Sep 4, 2023
1 parent e25a70d commit 40da5be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/gotrue/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ enum OtpType {
email
}

/// Messaging channel to use (e.g. whatsapp or sms)
enum OtpChannel {
sms,
whatsapp,
}

///Determines which sessions should be logged out.
///
///[global] means all sessions by this account will be signed out.
Expand Down
8 changes: 8 additions & 0 deletions packages/gotrue/lib/src/gotrue_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,16 @@ class GoTrueClient {
/// [password] is the password of the user
///
/// [data] sets [User.userMetadata] without an extra call to [updateUser]
///
/// [channel] Messaging channel to use (e.g. whatsapp or sms)
Future<AuthResponse> signUp({
String? email,
String? phone,
required String password,
String? emailRedirectTo,
Map<String, dynamic>? data,
String? captchaToken,
OtpChannel channel = OtpChannel.sms,
}) async {
assert((email != null && phone == null) || (email == null && phone != null),
'You must provide either an email or phone number');
Expand Down Expand Up @@ -191,6 +194,7 @@ class GoTrueClient {
'password': password,
'data': data,
'gotrue_meta_security': {'captcha_token': captchaToken},
'channel': channel.name,
};
final fetchOptions = GotrueRequestOptions(headers: _headers, body: body);
response = await _fetch.request('$_url/signup', RequestMethodType.post,
Expand Down Expand Up @@ -392,13 +396,16 @@ class GoTrueClient {
/// [data] can be used to set the user's metadata, which maps to the `auth.users.user_metadata` column.
///
/// [captchaToken] Verification token received when the user completes the captcha on the site.
///
/// [channel] Messaging channel to use (e.g. whatsapp or sms)
Future<void> signInWithOtp({
String? email,
String? phone,
String? emailRedirectTo,
bool? shouldCreateUser,
Map<String, dynamic>? data,
String? captchaToken,
OtpChannel channel = OtpChannel.sms,
}) async {
_removeSession();

Expand Down Expand Up @@ -437,6 +444,7 @@ class GoTrueClient {
'data': data ?? {},
'create_user': shouldCreateUser ?? true,
'gotrue_meta_security': {'captcha_token': captchaToken},
'channel': channel.name,
};
final fetchOptions = GotrueRequestOptions(headers: _headers, body: body);

Expand Down

0 comments on commit 40da5be

Please sign in to comment.