@@ -21,7 +21,9 @@ public final class AuthClient: Sendable {
21
21
22
22
private var api : APIClient { Dependencies [ clientID] . api }
23
23
var configuration : AuthClient . Configuration { Dependencies [ clientID] . configuration }
24
- private var codeVerifierStorage : CodeVerifierStorage { Dependencies [ clientID] . codeVerifierStorage }
24
+ private var codeVerifierStorage : CodeVerifierStorage {
25
+ Dependencies [ clientID] . codeVerifierStorage
26
+ }
25
27
private var date : @Sendable ( ) -> Date { Dependencies [ clientID] . date }
26
28
private var sessionManager : SessionManager { Dependencies [ clientID] . sessionManager }
27
29
private var eventEmitter : AuthStateChangeEventEmitter { Dependencies [ clientID] . eventEmitter }
@@ -77,10 +79,11 @@ public final class AuthClient: Sendable {
77
79
sessionManager: . live( clientID: clientID)
78
80
)
79
81
80
- observeAppLifecycleChanges ( )
82
+ Task { @ MainActor in observeAppLifecycleChanges ( ) }
81
83
}
82
84
83
85
#if canImport(ObjectiveC)
86
+ @MainActor
84
87
private func observeAppLifecycleChanges( ) {
85
88
#if canImport(UIKit)
86
89
#if canImport(WatchKit)
@@ -165,14 +168,20 @@ public final class AuthClient: Sendable {
165
168
/// Listen for auth state changes.
166
169
///
167
170
/// An `.initialSession` is always emitted when this method is called.
168
- public var authStateChanges : AsyncStream < (
169
- event: AuthChangeEvent ,
170
- session: Session ?
171
- ) > {
172
- let ( stream, continuation) = AsyncStream< (
173
- event: AuthChangeEvent,
174
- session: Session?
175
- ) > . makeStream( )
171
+ public var authStateChanges :
172
+ AsyncStream <
173
+ (
174
+ event: AuthChangeEvent ,
175
+ session: Session ?
176
+ )
177
+ >
178
+ {
179
+ let ( stream, continuation) = AsyncStream<
180
+ (
181
+ event: AuthChangeEvent,
182
+ session: Session?
183
+ )
184
+ > . makeStream ( )
176
185
177
186
Task {
178
187
let handle = await onAuthStateChange { event, session in
@@ -209,10 +218,12 @@ public final class AuthClient: Sendable {
209
218
url: configuration. url. appendingPathComponent ( " signup " ) ,
210
219
method: . post,
211
220
query: [
212
- ( redirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
213
- name: " redirect_to " ,
214
- value: $0. absoluteString
215
- ) } ,
221
+ ( redirectTo ?? configuration. redirectToURL) . map {
222
+ URLQueryItem (
223
+ name: " redirect_to " ,
224
+ value: $0. absoluteString
225
+ )
226
+ }
216
227
] . compactMap { $0 } ,
217
228
body: configuration. encoder. encode (
218
229
SignUpRequest (
@@ -401,10 +412,12 @@ public final class AuthClient: Sendable {
401
412
url: configuration. url. appendingPathComponent ( " otp " ) ,
402
413
method: . post,
403
414
query: [
404
- ( redirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
405
- name: " redirect_to " ,
406
- value: $0. absoluteString
407
- ) } ,
415
+ ( redirectTo ?? configuration. redirectToURL) . map {
416
+ URLQueryItem (
417
+ name: " redirect_to " ,
418
+ value: $0. absoluteString
419
+ )
420
+ }
408
421
] . compactMap { $0 } ,
409
422
body: configuration. encoder. encode (
410
423
OTPParams (
@@ -524,7 +537,8 @@ public final class AuthClient: Sendable {
524
537
let codeVerifier = codeVerifierStorage. get ( )
525
538
526
539
if codeVerifier == nil {
527
- logger? . error ( " code verifier not found, a code verifier should exist when calling this method. " )
540
+ logger? . error (
541
+ " code verifier not found, a code verifier should exist when calling this method. " )
528
542
}
529
543
530
544
let session : Session = try await api. execute (
@@ -878,7 +892,9 @@ public final class AuthClient: Sendable {
878
892
headers: [ . authorization: " Bearer \( accessToken) " ]
879
893
)
880
894
)
881
- } catch let AuthError . api( _, _, _, response) where [ 404 , 403 , 401 ] . contains ( response. statusCode) {
895
+ } catch let AuthError . api( _, _, _, response)
896
+ where [ 404 , 403 , 401 ] . contains ( response. statusCode)
897
+ {
882
898
// ignore 404s since user might not exist anymore
883
899
// ignore 401s, and 403s since an invalid or expired JWT should sign out the current session.
884
900
}
@@ -898,10 +914,12 @@ public final class AuthClient: Sendable {
898
914
url: configuration. url. appendingPathComponent ( " verify " ) ,
899
915
method: . post,
900
916
query: [
901
- ( redirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
902
- name: " redirect_to " ,
903
- value: $0. absoluteString
904
- ) } ,
917
+ ( redirectTo ?? configuration. redirectToURL) . map {
918
+ URLQueryItem (
919
+ name: " redirect_to " ,
920
+ value: $0. absoluteString
921
+ )
922
+ }
905
923
] . compactMap { $0 } ,
906
924
body: configuration. encoder. encode (
907
925
VerifyOTPParams . email (
@@ -991,10 +1009,12 @@ public final class AuthClient: Sendable {
991
1009
url: configuration. url. appendingPathComponent ( " resend " ) ,
992
1010
method: . post,
993
1011
query: [
994
- ( emailRedirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
995
- name: " redirect_to " ,
996
- value: $0. absoluteString
997
- ) } ,
1012
+ ( emailRedirectTo ?? configuration. redirectToURL) . map {
1013
+ URLQueryItem (
1014
+ name: " redirect_to " ,
1015
+ value: $0. absoluteString
1016
+ )
1017
+ }
998
1018
] . compactMap { $0 } ,
999
1019
body: configuration. encoder. encode (
1000
1020
ResendEmailParams (
@@ -1078,10 +1098,12 @@ public final class AuthClient: Sendable {
1078
1098
url: configuration. url. appendingPathComponent ( " user " ) ,
1079
1099
method: . put,
1080
1100
query: [
1081
- ( redirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
1082
- name: " redirect_to " ,
1083
- value: $0. absoluteString
1084
- ) } ,
1101
+ ( redirectTo ?? configuration. redirectToURL) . map {
1102
+ URLQueryItem (
1103
+ name: " redirect_to " ,
1104
+ value: $0. absoluteString
1105
+ )
1106
+ }
1085
1107
] . compactMap { $0 } ,
1086
1108
body: configuration. encoder. encode ( user)
1087
1109
)
@@ -1213,10 +1235,12 @@ public final class AuthClient: Sendable {
1213
1235
url: configuration. url. appendingPathComponent ( " recover " ) ,
1214
1236
method: . post,
1215
1237
query: [
1216
- ( redirectTo ?? configuration. redirectToURL) . map { URLQueryItem (
1217
- name: " redirect_to " ,
1218
- value: $0. absoluteString
1219
- ) } ,
1238
+ ( redirectTo ?? configuration. redirectToURL) . map {
1239
+ URLQueryItem (
1240
+ name: " redirect_to " ,
1241
+ value: $0. absoluteString
1242
+ )
1243
+ }
1220
1244
] . compactMap { $0 } ,
1221
1245
body: configuration. encoder. encode (
1222
1246
RecoverParams (
@@ -1300,7 +1324,7 @@ public final class AuthClient: Sendable {
1300
1324
}
1301
1325
1302
1326
var queryItems : [ URLQueryItem ] = [
1303
- URLQueryItem ( name: " provider " , value: provider. rawValue) ,
1327
+ URLQueryItem ( name: " provider " , value: provider. rawValue)
1304
1328
]
1305
1329
1306
1330
if let scopes {
0 commit comments