diff --git a/Sources/Auth/AuthClient.swift b/Sources/Auth/AuthClient.swift index d2c383f0..23ec63e8 100644 --- a/Sources/Auth/AuthClient.swift +++ b/Sources/Auth/AuthClient.swift @@ -243,12 +243,14 @@ public final class AuthClient: Sendable { /// - Parameters: /// - phone: User's phone number with international prefix. /// - password: Password for the user. + /// - channel: Messaging channel to use (e.g. whatsapp or sms). /// - data: Custom data object to store additional user metadata. /// - captchaToken: Optional captcha token for securing this endpoint. @discardableResult public func signUp( phone: String, password: String, + channel: MessagingChannel = .sms, data: [String: AnyJSON]? = nil, captchaToken: String? = nil ) async throws -> AuthResponse { @@ -260,6 +262,7 @@ public final class AuthClient: Sendable { SignUpRequest( password: password, phone: phone, + channel: channel, data: data, gotrueMetaSecurity: captchaToken.map(AuthMetaSecurity.init(captchaToken:)) ) diff --git a/Sources/Auth/Types.swift b/Sources/Auth/Types.swift index 3a56ea18..6e51684b 100644 --- a/Sources/Auth/Types.swift +++ b/Sources/Auth/Types.swift @@ -46,6 +46,7 @@ struct SignUpRequest: Codable, Hashable, Sendable { var email: String? var password: String? var phone: String? + var channel: MessagingChannel? var data: [String: AnyJSON]? var gotrueMetaSecurity: AuthMetaSecurity? var codeChallenge: String? diff --git a/Tests/AuthTests/RequestsTests.swift b/Tests/AuthTests/RequestsTests.swift index a2b36c79..1152c2d1 100644 --- a/Tests/AuthTests/RequestsTests.swift +++ b/Tests/AuthTests/RequestsTests.swift @@ -5,13 +5,14 @@ // Created by Guilherme Souza on 07/10/23. // -@testable import Auth import Helpers import InlineSnapshotTesting import SnapshotTesting import TestHelpers import XCTest +@testable import Auth + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -126,7 +127,7 @@ final class RequestsTests: XCTestCase { url, URL( string: - "http://localhost:54321/auth/v1/authorize?provider=github&scopes=read,write&redirect_to=https://dummy-url.com/redirect&extra_key=extra_value" + "http://localhost:54321/auth/v1/authorize?provider=github&scopes=read,write&redirect_to=https://dummy-url.com/redirect&extra_key=extra_value" )! ) } @@ -152,7 +153,7 @@ final class RequestsTests: XCTestCase { let url = URL( string: - "https://dummy-url.com/callback#access_token=accesstoken&expires_in=60&refresh_token=refreshtoken&token_type=bearer" + "https://dummy-url.com/callback#access_token=accesstoken&expires_in=60&refresh_token=refreshtoken&token_type=bearer" )! let session = try await sut.session(from: url) @@ -173,7 +174,7 @@ final class RequestsTests: XCTestCase { let url = URL( string: - "https://dummy-url.com/callback#access_token=accesstoken&expires_in=60&refresh_token=refreshtoken" + "https://dummy-url.com/callback#access_token=accesstoken&expires_in=60&refresh_token=refreshtoken" )! do { @@ -430,7 +431,8 @@ final class RequestsTests: XCTestCase { Dependencies[sut.clientID].sessionStorage.store(.validSession) await assert { - _ = try await sut.mfa.enroll(params: MFAEnrollParams(issuer: "supabase.com", friendlyName: "test")) + _ = try await sut.mfa.enroll( + params: MFAEnrollParams(issuer: "supabase.com", friendlyName: "test")) } } @@ -480,7 +482,8 @@ final class RequestsTests: XCTestCase { Dependencies[sut.clientID].sessionStorage.store(.validSession) await assert { - _ = try await sut.mfa.verify(params: .init(factorId: "123", challengeId: "123", code: "123456")) + _ = try await sut.mfa.verify( + params: .init(factorId: "123", challengeId: "123", code: "123456")) } } diff --git a/Tests/AuthTests/__Snapshots__/RequestsTests/testSignUpWithPhoneAndPassword.1.txt b/Tests/AuthTests/__Snapshots__/RequestsTests/testSignUpWithPhoneAndPassword.1.txt index 7bcbc227..ef8b6abd 100644 --- a/Tests/AuthTests/__Snapshots__/RequestsTests/testSignUpWithPhoneAndPassword.1.txt +++ b/Tests/AuthTests/__Snapshots__/RequestsTests/testSignUpWithPhoneAndPassword.1.txt @@ -4,5 +4,5 @@ curl \ --header "Content-Type: application/json" \ --header "X-Client-Info: gotrue-swift/x.y.z" \ --header "X-Supabase-Api-Version: 2024-01-01" \ - --data "{\"data\":{\"custom_key\":\"custom_value\"},\"gotrue_meta_security\":{\"captcha_token\":\"dummy-captcha\"},\"password\":\"the.pass\",\"phone\":\"+1 202-918-2132\"}" \ + --data "{\"channel\":\"sms\",\"data\":{\"custom_key\":\"custom_value\"},\"gotrue_meta_security\":{\"captcha_token\":\"dummy-captcha\"},\"password\":\"the.pass\",\"phone\":\"+1 202-918-2132\"}" \ "http://localhost:54321/auth/v1/signup" \ No newline at end of file