Skip to content

Commit 3a36ab7

Browse files
authored
fix(auth): add missing channel param to signUp method (#625)
1 parent 7a88591 commit 3a36ab7

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

Sources/Auth/AuthClient.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,14 @@ public final class AuthClient: Sendable {
243243
/// - Parameters:
244244
/// - phone: User's phone number with international prefix.
245245
/// - password: Password for the user.
246+
/// - channel: Messaging channel to use (e.g. whatsapp or sms).
246247
/// - data: Custom data object to store additional user metadata.
247248
/// - captchaToken: Optional captcha token for securing this endpoint.
248249
@discardableResult
249250
public func signUp(
250251
phone: String,
251252
password: String,
253+
channel: MessagingChannel = .sms,
252254
data: [String: AnyJSON]? = nil,
253255
captchaToken: String? = nil
254256
) async throws -> AuthResponse {
@@ -260,6 +262,7 @@ public final class AuthClient: Sendable {
260262
SignUpRequest(
261263
password: password,
262264
phone: phone,
265+
channel: channel,
263266
data: data,
264267
gotrueMetaSecurity: captchaToken.map(AuthMetaSecurity.init(captchaToken:))
265268
)

Sources/Auth/Types.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct SignUpRequest: Codable, Hashable, Sendable {
4646
var email: String?
4747
var password: String?
4848
var phone: String?
49+
var channel: MessagingChannel?
4950
var data: [String: AnyJSON]?
5051
var gotrueMetaSecurity: AuthMetaSecurity?
5152
var codeChallenge: String?

Tests/AuthTests/RequestsTests.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
// Created by Guilherme Souza on 07/10/23.
66
//
77

8-
@testable import Auth
98
import Helpers
109
import InlineSnapshotTesting
1110
import SnapshotTesting
1211
import TestHelpers
1312
import XCTest
1413

14+
@testable import Auth
15+
1516
#if canImport(FoundationNetworking)
1617
import FoundationNetworking
1718
#endif
@@ -126,7 +127,7 @@ final class RequestsTests: XCTestCase {
126127
url,
127128
URL(
128129
string:
129-
"http://localhost:54321/auth/v1/authorize?provider=github&scopes=read,write&redirect_to=https://dummy-url.com/redirect&extra_key=extra_value"
130+
"http://localhost:54321/auth/v1/authorize?provider=github&scopes=read,write&redirect_to=https://dummy-url.com/redirect&extra_key=extra_value"
130131
)!
131132
)
132133
}
@@ -152,7 +153,7 @@ final class RequestsTests: XCTestCase {
152153

153154
let url = URL(
154155
string:
155-
"https://dummy-url.com/callback#access_token=accesstoken&expires_in=60&refresh_token=refreshtoken&token_type=bearer"
156+
"https://dummy-url.com/callback#access_token=accesstoken&expires_in=60&refresh_token=refreshtoken&token_type=bearer"
156157
)!
157158

158159
let session = try await sut.session(from: url)
@@ -173,7 +174,7 @@ final class RequestsTests: XCTestCase {
173174

174175
let url = URL(
175176
string:
176-
"https://dummy-url.com/callback#access_token=accesstoken&expires_in=60&refresh_token=refreshtoken"
177+
"https://dummy-url.com/callback#access_token=accesstoken&expires_in=60&refresh_token=refreshtoken"
177178
)!
178179

179180
do {
@@ -430,7 +431,8 @@ final class RequestsTests: XCTestCase {
430431
Dependencies[sut.clientID].sessionStorage.store(.validSession)
431432

432433
await assert {
433-
_ = try await sut.mfa.enroll(params: MFAEnrollParams(issuer: "supabase.com", friendlyName: "test"))
434+
_ = try await sut.mfa.enroll(
435+
params: MFAEnrollParams(issuer: "supabase.com", friendlyName: "test"))
434436
}
435437
}
436438

@@ -480,7 +482,8 @@ final class RequestsTests: XCTestCase {
480482
Dependencies[sut.clientID].sessionStorage.store(.validSession)
481483

482484
await assert {
483-
_ = try await sut.mfa.verify(params: .init(factorId: "123", challengeId: "123", code: "123456"))
485+
_ = try await sut.mfa.verify(
486+
params: .init(factorId: "123", challengeId: "123", code: "123456"))
484487
}
485488
}
486489

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ curl \
44
--header "Content-Type: application/json" \
55
--header "X-Client-Info: gotrue-swift/x.y.z" \
66
--header "X-Supabase-Api-Version: 2024-01-01" \
7-
--data "{\"data\":{\"custom_key\":\"custom_value\"},\"gotrue_meta_security\":{\"captcha_token\":\"dummy-captcha\"},\"password\":\"the.pass\",\"phone\":\"+1 202-918-2132\"}" \
7+
--data "{\"channel\":\"sms\",\"data\":{\"custom_key\":\"custom_value\"},\"gotrue_meta_security\":{\"captcha_token\":\"dummy-captcha\"},\"password\":\"the.pass\",\"phone\":\"+1 202-918-2132\"}" \
88
"http://localhost:54321/auth/v1/signup"

0 commit comments

Comments
 (0)