@@ -43,7 +43,8 @@ public final class AuthClient: Sendable {
43
43
configuration: configuration,
44
44
sessionRefresher: SessionRefresher { [ weak self] in
45
45
try await self ? . refreshSession ( refreshToken: $0) ?? . empty
46
- }
46
+ } ,
47
+ http: HTTPClient ( configuration: configuration)
47
48
)
48
49
}
49
50
@@ -105,7 +106,7 @@ public final class AuthClient: Sendable {
105
106
106
107
return try await _signUp (
107
108
request: . init(
108
- path : " / signup" ,
109
+ url : configuration . url . appendingPathComponent ( " signup " ) ,
109
110
method: . post,
110
111
query: [
111
112
( redirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
@@ -141,7 +142,7 @@ public final class AuthClient: Sendable {
141
142
) async throws -> AuthResponse {
142
143
try await _signUp (
143
144
request: . init(
144
- path : " / signup" ,
145
+ url : configuration . url . appendingPathComponent ( " signup " ) ,
145
146
method: . post,
146
147
body: configuration. encoder. encode (
147
148
SignUpRequest (
@@ -155,7 +156,7 @@ public final class AuthClient: Sendable {
155
156
)
156
157
}
157
158
158
- private func _signUp( request: Request ) async throws -> AuthResponse {
159
+ private func _signUp( request: HTTPRequest ) async throws -> AuthResponse {
159
160
await sessionManager. remove ( )
160
161
let response = try await api. execute ( request) . decoded (
161
162
as: AuthResponse . self,
@@ -179,7 +180,7 @@ public final class AuthClient: Sendable {
179
180
) async throws -> Session {
180
181
try await _signIn (
181
182
request: . init(
182
- path : " / token" ,
183
+ url : configuration . url . appendingPathComponent ( " token " ) ,
183
184
method: . post,
184
185
query: [ URLQueryItem ( name: " grant_type " , value: " password " ) ] ,
185
186
body: configuration. encoder. encode (
@@ -202,7 +203,7 @@ public final class AuthClient: Sendable {
202
203
) async throws -> Session {
203
204
try await _signIn (
204
205
request: . init(
205
- path : " / token" ,
206
+ url : configuration . url . appendingPathComponent ( " token " ) ,
206
207
method: . post,
207
208
query: [ URLQueryItem ( name: " grant_type " , value: " password " ) ] ,
208
209
body: configuration. encoder. encode (
@@ -222,7 +223,7 @@ public final class AuthClient: Sendable {
222
223
public func signInWithIdToken( credentials: OpenIDConnectCredentials ) async throws -> Session {
223
224
try await _signIn (
224
225
request: . init(
225
- path : " / token" ,
226
+ url : configuration . url . appendingPathComponent ( " token " ) ,
226
227
method: . post,
227
228
query: [ URLQueryItem ( name: " grant_type " , value: " id_token " ) ] ,
228
229
body: configuration. encoder. encode ( credentials)
@@ -242,8 +243,8 @@ public final class AuthClient: Sendable {
242
243
captchaToken: String ? = nil
243
244
) async throws -> Session {
244
245
try await _signIn (
245
- request: Request (
246
- path : " / signup" ,
246
+ request: HTTPRequest (
247
+ url : configuration . url . appendingPathComponent ( " signup " ) ,
247
248
method: . post,
248
249
body: configuration. encoder. encode (
249
250
SignUpRequest (
@@ -255,7 +256,7 @@ public final class AuthClient: Sendable {
255
256
)
256
257
}
257
258
258
- private func _signIn( request: Request ) async throws -> Session {
259
+ private func _signIn( request: HTTPRequest ) async throws -> Session {
259
260
await sessionManager. remove ( )
260
261
261
262
let session = try await api. execute ( request) . decoded (
@@ -293,7 +294,7 @@ public final class AuthClient: Sendable {
293
294
294
295
_ = try await api. execute (
295
296
. init(
296
- path : " / otp" ,
297
+ url : configuration . url . appendingPathComponent ( " otp " ) ,
297
298
method: . post,
298
299
query: [
299
300
( redirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
@@ -336,7 +337,7 @@ public final class AuthClient: Sendable {
336
337
await sessionManager. remove ( )
337
338
_ = try await api. execute (
338
339
. init(
339
- path : " / otp" ,
340
+ url : configuration . url . appendingPathComponent ( " otp " ) ,
340
341
method: . post,
341
342
body: configuration. encoder. encode (
342
343
OTPParams (
@@ -368,8 +369,8 @@ public final class AuthClient: Sendable {
368
369
let ( codeChallenge, codeChallengeMethod) = prepareForPKCE ( )
369
370
370
371
return try await api. execute (
371
- Request (
372
- path : " / sso" ,
372
+ HTTPRequest (
373
+ url : configuration . url . appendingPathComponent ( " sso " ) ,
373
374
method: . post,
374
375
body: configuration. encoder. encode (
375
376
SignInWithSSORequest (
@@ -403,8 +404,8 @@ public final class AuthClient: Sendable {
403
404
let ( codeChallenge, codeChallengeMethod) = prepareForPKCE ( )
404
405
405
406
return try await api. execute (
406
- Request (
407
- path : " / sso" ,
407
+ HTTPRequest (
408
+ url : configuration . url . appendingPathComponent ( " sso " ) ,
408
409
method: . post,
409
410
body: configuration. encoder. encode (
410
411
SignInWithSSORequest (
@@ -429,7 +430,7 @@ public final class AuthClient: Sendable {
429
430
430
431
let session : Session = try await api. execute (
431
432
. init(
432
- path : " / token" ,
433
+ url : configuration . url . appendingPathComponent ( " token " ) ,
433
434
method: . post,
434
435
query: [ URLQueryItem ( name: " grant_type " , value: " pkce " ) ] ,
435
436
body: configuration. encoder. encode (
@@ -622,7 +623,7 @@ public final class AuthClient: Sendable {
622
623
623
624
let user = try await api. execute (
624
625
. init(
625
- path : " / user" ,
626
+ url : configuration . url . appendingPathComponent ( " user " ) ,
626
627
method: . get,
627
628
headers: [ " Authorization " : " \( tokenType) \( accessToken) " ]
628
629
)
@@ -703,7 +704,7 @@ public final class AuthClient: Sendable {
703
704
704
705
try await api. authorizedExecute (
705
706
. init(
706
- path : " / logout" ,
707
+ url : configuration . url . appendingPathComponent ( " logout " ) ,
707
708
method: . post,
708
709
query: [ URLQueryItem ( name: " scope " , value: scope. rawValue) ]
709
710
)
@@ -737,7 +738,7 @@ public final class AuthClient: Sendable {
737
738
) async throws -> AuthResponse {
738
739
try await _verifyOTP (
739
740
request: . init(
740
- path : " / verify" ,
741
+ url : configuration . url . appendingPathComponent ( " verify " ) ,
741
742
method: . post,
742
743
query: [
743
744
( redirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
@@ -770,7 +771,7 @@ public final class AuthClient: Sendable {
770
771
) async throws -> AuthResponse {
771
772
try await _verifyOTP (
772
773
request: . init(
773
- path : " / verify" ,
774
+ url : configuration . url . appendingPathComponent ( " verify " ) ,
774
775
method: . post,
775
776
body: configuration. encoder. encode (
776
777
VerifyOTPParams . mobile (
@@ -788,7 +789,7 @@ public final class AuthClient: Sendable {
788
789
}
789
790
790
791
private func _verifyOTP(
791
- request: Request ,
792
+ request: HTTPRequest ,
792
793
shouldRemoveSession: Bool
793
794
) async throws -> AuthResponse {
794
795
if shouldRemoveSession {
@@ -823,8 +824,8 @@ public final class AuthClient: Sendable {
823
824
}
824
825
825
826
_ = try await api. execute (
826
- Request (
827
- path : " / resend" ,
827
+ HTTPRequest (
828
+ url : configuration . url . appendingPathComponent ( " resend " ) ,
828
829
method: . post,
829
830
query: [
830
831
( emailRedirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
@@ -860,8 +861,8 @@ public final class AuthClient: Sendable {
860
861
}
861
862
862
863
return try await api. execute (
863
- Request (
864
- path : " / resend" ,
864
+ HTTPRequest (
865
+ url : configuration . url . appendingPathComponent ( " resend " ) ,
865
866
method: . post,
866
867
body: configuration. encoder. encode (
867
868
ResendMobileParams (
@@ -878,7 +879,10 @@ public final class AuthClient: Sendable {
878
879
/// Sends a re-authentication OTP to the user's email or phone number.
879
880
public func reauthenticate( ) async throws {
880
881
try await api. authorizedExecute (
881
- Request ( path: " /reauthenticate " , method: . get)
882
+ HTTPRequest (
883
+ url: configuration. url. appendingPathComponent ( " reauthenticate " ) ,
884
+ method: . get
885
+ )
882
886
)
883
887
}
884
888
@@ -889,7 +893,7 @@ public final class AuthClient: Sendable {
889
893
/// Should be used only when you require the most current user data. For faster results,
890
894
/// session.user is recommended.
891
895
public func user( jwt: String ? = nil ) async throws -> User {
892
- var request = Request ( path : " / user" , method: . get)
896
+ var request = HTTPRequest ( url : configuration . url . appendingPathComponent ( " user " ) , method: . get)
893
897
894
898
if let jwt {
895
899
request. headers [ " Authorization " ] = " Bearer \( jwt) "
@@ -912,7 +916,11 @@ public final class AuthClient: Sendable {
912
916
913
917
var session = try await sessionManager. session ( )
914
918
let updatedUser = try await api. authorizedExecute (
915
- . init( path: " /user " , method: . put, body: configuration. encoder. encode ( user) )
919
+ . init(
920
+ url: configuration. url. appendingPathComponent ( " user " ) ,
921
+ method: . put,
922
+ body: configuration. encoder. encode ( user)
923
+ )
916
924
) . decoded ( as: User . self, decoder: configuration. decoder)
917
925
session. user = updatedUser
918
926
try await sessionManager. update ( session)
@@ -954,7 +962,7 @@ public final class AuthClient: Sendable {
954
962
}
955
963
956
964
let response = try await api. authorizedExecute (
957
- Request (
965
+ HTTPRequest (
958
966
url: url,
959
967
method: . get
960
968
)
@@ -968,8 +976,8 @@ public final class AuthClient: Sendable {
968
976
/// with that identity once it's unlinked.
969
977
public func unlinkIdentity( _ identity: UserIdentity ) async throws {
970
978
try await api. authorizedExecute (
971
- Request (
972
- path : " / user/identities/\( identity. identityId) " ,
979
+ HTTPRequest (
980
+ url : configuration . url . appendingPathComponent ( " user/identities/ \( identity. identityId) " ) ,
973
981
method: . delete
974
982
)
975
983
)
@@ -985,7 +993,7 @@ public final class AuthClient: Sendable {
985
993
986
994
_ = try await api. execute (
987
995
. init(
988
- path : " / recover" ,
996
+ url : configuration . url . appendingPathComponent ( " recover " ) ,
989
997
method: . post,
990
998
query: [
991
999
( redirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
@@ -1019,7 +1027,7 @@ public final class AuthClient: Sendable {
1019
1027
1020
1028
let session = try await api. execute (
1021
1029
. init(
1022
- path : " / token" ,
1030
+ url : configuration . url . appendingPathComponent ( " token " ) ,
1023
1031
method: . post,
1024
1032
query: [ URLQueryItem ( name: " grant_type " , value: " refresh_token " ) ] ,
1025
1033
body: configuration. encoder. encode ( credentials)
0 commit comments