Skip to content

Commit 600c400

Browse files
authored
feat(auth): add whatsapp channel option to signInWithOTP (#287)
* feat(auth): add whatsapp channel option to signInWithOTP * test: record changed snapshot test
1 parent 0b19580 commit 600c400

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Sources/Auth/AuthClient.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,16 @@ public actor AuthClient {
425425
///
426426
/// - Parameters:
427427
/// - phone: User's phone with international prefix.
428+
/// - channel: Messaging channel to use (e.g `whatsapp` or `sms`), defaults to `sms`.
428429
/// - shouldCreateUser: Creates a new user, defaults to `true`.
429430
/// - data: User's metadata.
430431
/// - captchaToken: Captcha verification token.
432+
///
433+
/// - Note: You need to configure a WhatsApp sender on Twillo if you are using phone sign in with
434+
/// the `whatsapp` channel.
431435
public func signInWithOTP(
432436
phone: String,
437+
channel: MessagingChannel = .sms,
433438
shouldCreateUser: Bool = true,
434439
data: [String: AnyJSON]? = nil,
435440
captchaToken: String? = nil
@@ -443,6 +448,7 @@ public actor AuthClient {
443448
OTPParams(
444449
phone: phone,
445450
createUser: shouldCreateUser,
451+
channel: channel,
446452
data: data,
447453
gotrueMetaSecurity: captchaToken.map(AuthMetaSecurity.init(captchaToken:))
448454
)

Sources/Auth/Types.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ struct OTPParams: Codable, Hashable, Sendable {
297297
var email: String?
298298
var phone: String?
299299
var createUser: Bool
300+
var channel: MessagingChannel?
300301
var data: [String: AnyJSON]?
301302
var gotrueMetaSecurity: AuthMetaSecurity?
302303
var codeChallenge: String?
@@ -658,3 +659,8 @@ public struct WeakPassword: Codable, Hashable, Sendable {
658659
struct DeleteUserRequest: Encodable {
659660
let shouldSoftDelete: Bool
660661
}
662+
663+
public enum MessagingChannel: String, Codable, Sendable {
664+
case sms
665+
case whatsapp
666+
}

Tests/AuthTests/__Snapshots__/RequestsTests/testSignInWithOTPUsingPhone.1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ curl \
33
--header "Apikey: dummy.api.key" \
44
--header "Content-Type: application/json" \
55
--header "X-Client-Info: gotrue-swift/x.y.z" \
6-
--data "{\"create_user\":true,\"data\":{\"custom_key\":\"custom_value\"},\"gotrue_meta_security\":{\"captcha_token\":\"dummy-captcha\"},\"phone\":\"+1 202-918-2132\"}" \
6+
--data "{\"channel\":\"sms\",\"create_user\":true,\"data\":{\"custom_key\":\"custom_value\"},\"gotrue_meta_security\":{\"captcha_token\":\"dummy-captcha\"},\"phone\":\"+1 202-918-2132\"}" \
77
"http://localhost:54321/auth/v1/otp"

0 commit comments

Comments
 (0)