@@ -21,7 +21,9 @@ public final class AuthClient: Sendable {
2121
2222 private var api : APIClient { Dependencies [ clientID] . api }
2323 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+ }
2527 private var date : @Sendable ( ) -> Date { Dependencies [ clientID] . date }
2628 private var sessionManager : SessionManager { Dependencies [ clientID] . sessionManager }
2729 private var eventEmitter : AuthStateChangeEventEmitter { Dependencies [ clientID] . eventEmitter }
@@ -77,10 +79,11 @@ public final class AuthClient: Sendable {
7779 sessionManager: . live( clientID: clientID)
7880 )
7981
80- observeAppLifecycleChanges ( )
82+ Task { @ MainActor in observeAppLifecycleChanges ( ) }
8183 }
8284
8385 #if canImport(ObjectiveC)
86+ @MainActor
8487 private func observeAppLifecycleChanges( ) {
8588 #if canImport(UIKit)
8689 #if canImport(WatchKit)
@@ -165,14 +168,20 @@ public final class AuthClient: Sendable {
165168 /// Listen for auth state changes.
166169 ///
167170 /// 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 ( )
176185
177186 Task {
178187 let handle = await onAuthStateChange { event, session in
@@ -209,10 +218,12 @@ public final class AuthClient: Sendable {
209218 url: configuration. url. appendingPathComponent ( " signup " ) ,
210219 method: . post,
211220 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+ }
216227 ] . compactMap { $0 } ,
217228 body: configuration. encoder. encode (
218229 SignUpRequest (
@@ -401,10 +412,12 @@ public final class AuthClient: Sendable {
401412 url: configuration. url. appendingPathComponent ( " otp " ) ,
402413 method: . post,
403414 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+ }
408421 ] . compactMap { $0 } ,
409422 body: configuration. encoder. encode (
410423 OTPParams (
@@ -524,7 +537,8 @@ public final class AuthClient: Sendable {
524537 let codeVerifier = codeVerifierStorage. get ( )
525538
526539 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. " )
528542 }
529543
530544 let session : Session = try await api. execute (
@@ -878,7 +892,9 @@ public final class AuthClient: Sendable {
878892 headers: [ . authorization: " Bearer \( accessToken) " ]
879893 )
880894 )
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+ {
882898 // ignore 404s since user might not exist anymore
883899 // ignore 401s, and 403s since an invalid or expired JWT should sign out the current session.
884900 }
@@ -898,10 +914,12 @@ public final class AuthClient: Sendable {
898914 url: configuration. url. appendingPathComponent ( " verify " ) ,
899915 method: . post,
900916 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+ }
905923 ] . compactMap { $0 } ,
906924 body: configuration. encoder. encode (
907925 VerifyOTPParams . email (
@@ -991,10 +1009,12 @@ public final class AuthClient: Sendable {
9911009 url: configuration. url. appendingPathComponent ( " resend " ) ,
9921010 method: . post,
9931011 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+ }
9981018 ] . compactMap { $0 } ,
9991019 body: configuration. encoder. encode (
10001020 ResendEmailParams (
@@ -1078,10 +1098,12 @@ public final class AuthClient: Sendable {
10781098 url: configuration. url. appendingPathComponent ( " user " ) ,
10791099 method: . put,
10801100 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+ }
10851107 ] . compactMap { $0 } ,
10861108 body: configuration. encoder. encode ( user)
10871109 )
@@ -1213,10 +1235,12 @@ public final class AuthClient: Sendable {
12131235 url: configuration. url. appendingPathComponent ( " recover " ) ,
12141236 method: . post,
12151237 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+ }
12201244 ] . compactMap { $0 } ,
12211245 body: configuration. encoder. encode (
12221246 RecoverParams (
@@ -1300,7 +1324,7 @@ public final class AuthClient: Sendable {
13001324 }
13011325
13021326 var queryItems : [ URLQueryItem ] = [
1303- URLQueryItem ( name: " provider " , value: provider. rawValue) ,
1327+ URLQueryItem ( name: " provider " , value: provider. rawValue)
13041328 ]
13051329
13061330 if let scopes {
0 commit comments