1
1
import ConcurrencyExtras
2
2
import Foundation
3
- import Helpers
4
3
import HTTPTypes
4
+ import Helpers
5
5
6
6
#if canImport(AuthenticationServices)
7
7
import AuthenticationServices
@@ -219,14 +219,15 @@ public final class AuthClient: Sendable {
219
219
method: . post,
220
220
url: configuration. url
221
221
. appendingPathComponent ( " signup " )
222
- . appendingQueryItems ( [
223
- ( redirectTo ?? configuration. redirectToURL) . map {
224
- URLQueryItem (
225
- name: " redirect_to " ,
226
- value: $0. absoluteString
227
- )
228
- }
229
- ] . compactMap { $0 } )
222
+ . appendingQueryItems (
223
+ [
224
+ ( redirectTo ?? configuration. redirectToURL) . map {
225
+ URLQueryItem (
226
+ name: " redirect_to " ,
227
+ value: $0. absoluteString
228
+ )
229
+ }
230
+ ] . compactMap { $0 } )
230
231
) ,
231
232
from: configuration. encoder. encode (
232
233
SignUpRequest (
@@ -270,9 +271,12 @@ public final class AuthClient: Sendable {
270
271
)
271
272
}
272
273
273
- private func _signUp( for request: HTTPRequest , from bodyData: Data ? ) async throws -> AuthResponse {
274
+ private func _signUp(
275
+ for request: HTTPRequest ,
276
+ from bodyData: Data ?
277
+ ) async throws -> AuthResponse {
274
278
let ( data, _) = try await api. execute ( for: request, from: bodyData)
275
-
279
+
276
280
let response = try configuration. decoder. decode ( AuthResponse . self, from: data)
277
281
278
282
if let session = response. session {
@@ -381,7 +385,7 @@ public final class AuthClient: Sendable {
381
385
382
386
private func _signIn( for request: HTTPRequest , from bodyData: Data ? ) async throws -> Session {
383
387
let ( data, _) = try await api. execute ( for: request, from: bodyData)
384
-
388
+
385
389
let session = try configuration. decoder. decode ( Session . self, from: data)
386
390
387
391
await sessionManager. update ( session)
@@ -415,14 +419,15 @@ public final class AuthClient: Sendable {
415
419
method: . post,
416
420
url: configuration. url
417
421
. appendingPathComponent ( " otp " )
418
- . appendingQueryItems ( [
419
- ( redirectTo ?? configuration. redirectToURL) . map {
420
- URLQueryItem (
421
- name: " redirect_to " ,
422
- value: $0. absoluteString
423
- )
424
- }
425
- ] . compactMap { $0 } )
422
+ . appendingQueryItems (
423
+ [
424
+ ( redirectTo ?? configuration. redirectToURL) . map {
425
+ URLQueryItem (
426
+ name: " redirect_to " ,
427
+ value: $0. absoluteString
428
+ )
429
+ }
430
+ ] . compactMap { $0 } )
426
431
) ,
427
432
from: configuration. encoder. encode (
428
433
OTPParams (
@@ -500,7 +505,7 @@ public final class AuthClient: Sendable {
500
505
)
501
506
)
502
507
)
503
-
508
+
504
509
return try configuration. decoder. decode ( SSOResponse . self, from: data)
505
510
}
506
511
@@ -534,7 +539,7 @@ public final class AuthClient: Sendable {
534
539
)
535
540
)
536
541
)
537
-
542
+
538
543
return try configuration. decoder. decode ( SSOResponse . self, from: data)
539
544
}
540
545
@@ -561,7 +566,7 @@ public final class AuthClient: Sendable {
561
566
]
562
567
)
563
568
)
564
-
569
+
565
570
let session = try configuration. decoder. decode ( Session . self, from: data)
566
571
567
572
codeVerifierStorage. set ( nil )
@@ -813,9 +818,9 @@ public final class AuthClient: Sendable {
813
818
) ,
814
819
from: nil
815
820
)
816
-
821
+
817
822
let user = try configuration. decoder. decode ( User . self, from: data)
818
-
823
+
819
824
let session = Session (
820
825
providerToken: providerToken,
821
826
providerRefreshToken: providerRefreshToken,
@@ -924,7 +929,7 @@ public final class AuthClient: Sendable {
924
929
from: nil
925
930
)
926
931
} catch let AuthError . api( _, _, _, response)
927
- where [ 404 , 403 , 401 ] . contains ( response. status. code)
932
+ where [ 404 , 403 , 401 ] . contains ( response. status. code)
928
933
{
929
934
// ignore 404s since user might not exist anymore
930
935
// ignore 401s, and 403s since an invalid or expired JWT should sign out the current session.
@@ -945,15 +950,16 @@ public final class AuthClient: Sendable {
945
950
method: . post,
946
951
url: configuration. url
947
952
. appendingPathComponent ( " verify " )
948
- . appendingQueryItems ( [
949
- ( redirectTo ?? configuration. redirectToURL) . map {
950
- URLQueryItem (
951
- name: " redirect_to " ,
952
- value: $0. absoluteString
953
- )
954
- }
955
- ] . compactMap { $0 } )
956
- ) ,
953
+ . appendingQueryItems (
954
+ [
955
+ ( redirectTo ?? configuration. redirectToURL) . map {
956
+ URLQueryItem (
957
+ name: " redirect_to " ,
958
+ value: $0. absoluteString
959
+ )
960
+ }
961
+ ] . compactMap { $0 } )
962
+ ) ,
957
963
from: configuration. encoder. encode (
958
964
VerifyOTPParams . email (
959
965
VerifyEmailOTPParams (
@@ -1012,9 +1018,12 @@ public final class AuthClient: Sendable {
1012
1018
)
1013
1019
}
1014
1020
1015
- private func _verifyOTP( for request: HTTPRequest , from bodyData: Data ? ) async throws -> AuthResponse {
1021
+ private func _verifyOTP(
1022
+ for request: HTTPRequest ,
1023
+ from bodyData: Data ?
1024
+ ) async throws -> AuthResponse {
1016
1025
let ( data, _) = try await api. execute ( for: request, from: bodyData)
1017
-
1026
+
1018
1027
let response = try configuration. decoder. decode ( AuthResponse . self, from: data)
1019
1028
1020
1029
if let session = response. session {
@@ -1040,14 +1049,15 @@ public final class AuthClient: Sendable {
1040
1049
method: . post,
1041
1050
url: configuration. url
1042
1051
. appendingPathComponent ( " resend " )
1043
- . appendingQueryItems ( [
1044
- ( emailRedirectTo ?? configuration. redirectToURL) . map {
1045
- URLQueryItem (
1046
- name: " redirect_to " ,
1047
- value: $0. absoluteString
1048
- )
1049
- }
1050
- ] . compactMap { $0 } )
1052
+ . appendingQueryItems (
1053
+ [
1054
+ ( emailRedirectTo ?? configuration. redirectToURL) . map {
1055
+ URLQueryItem (
1056
+ name: " redirect_to " ,
1057
+ value: $0. absoluteString
1058
+ )
1059
+ }
1060
+ ] . compactMap { $0 } )
1051
1061
) ,
1052
1062
from: configuration. encoder. encode (
1053
1063
ResendEmailParams (
@@ -1084,7 +1094,7 @@ public final class AuthClient: Sendable {
1084
1094
)
1085
1095
)
1086
1096
)
1087
-
1097
+
1088
1098
return try configuration. decoder. decode ( ResendMobileResponse . self, from: data)
1089
1099
}
1090
1100
@@ -1113,7 +1123,7 @@ public final class AuthClient: Sendable {
1113
1123
if let jwt {
1114
1124
request. headerFields [ . authorization] = " Bearer \( jwt) "
1115
1125
}
1116
-
1126
+
1117
1127
let ( data, _) = try await api. authorizedExecute ( for: request, from: nil )
1118
1128
return try configuration. decoder. decode ( User . self, from: data)
1119
1129
}
@@ -1135,20 +1145,21 @@ public final class AuthClient: Sendable {
1135
1145
method: . put,
1136
1146
url: configuration. url
1137
1147
. appendingPathComponent ( " user " )
1138
- . appendingQueryItems ( [
1139
- ( redirectTo ?? configuration. redirectToURL) . map {
1140
- URLQueryItem (
1141
- name: " redirect_to " ,
1142
- value: $0. absoluteString
1143
- )
1144
- }
1145
- ] . compactMap { $0 } )
1148
+ . appendingQueryItems (
1149
+ [
1150
+ ( redirectTo ?? configuration. redirectToURL) . map {
1151
+ URLQueryItem (
1152
+ name: " redirect_to " ,
1153
+ value: $0. absoluteString
1154
+ )
1155
+ }
1156
+ ] . compactMap { $0 } )
1146
1157
) ,
1147
1158
from: configuration. encoder. encode ( user)
1148
1159
)
1149
-
1160
+
1150
1161
let updatedUser = try configuration. decoder. decode ( User . self, from: data)
1151
-
1162
+
1152
1163
session. user = updatedUser
1153
1164
await sessionManager. update ( session)
1154
1165
eventEmitter. emit ( . userUpdated, session: session)
@@ -1279,14 +1290,15 @@ public final class AuthClient: Sendable {
1279
1290
method: . post,
1280
1291
url: configuration. url
1281
1292
. appendingPathComponent ( " recover " )
1282
- . appendingQueryItems ( [
1283
- ( redirectTo ?? configuration. redirectToURL) . map {
1284
- URLQueryItem (
1285
- name: " redirect_to " ,
1286
- value: $0. absoluteString
1287
- )
1288
- }
1289
- ] . compactMap { $0 } )
1293
+ . appendingQueryItems (
1294
+ [
1295
+ ( redirectTo ?? configuration. redirectToURL) . map {
1296
+ URLQueryItem (
1297
+ name: " redirect_to " ,
1298
+ value: $0. absoluteString
1299
+ )
1300
+ }
1301
+ ] . compactMap { $0 } )
1290
1302
) ,
1291
1303
from: configuration. encoder. encode (
1292
1304
RecoverParams (
0 commit comments