@@ -300,9 +300,9 @@ extension Auth: AuthInterop {
300300 Task {
301301 do {
302302 let response = try await self . backend. call ( with: request)
303- Auth . wrapMainAsync ( callback: completion, withParam : response. signinMethods, error : nil )
303+ Auth . wrapMainAsync ( callback: completion, with : . success ( response. signinMethods) )
304304 } catch {
305- Auth . wrapMainAsync ( callback: completion, withParam : nil , error: error )
305+ Auth . wrapMainAsync ( callback: completion, with : . failure ( error) )
306306 }
307307 }
308308 }
@@ -365,9 +365,9 @@ extension Auth: AuthInterop {
365365 withEmail: email,
366366 password: password
367367 )
368- decoratedCallback ( authData, nil )
368+ decoratedCallback ( . success ( authData) )
369369 } catch {
370- decoratedCallback ( nil , error)
370+ decoratedCallback ( . failure ( error) )
371371 }
372372 }
373373 }
@@ -463,9 +463,9 @@ extension Auth: AuthInterop {
463463 do {
464464 let authData = try await self . internalSignInAndRetrieveData ( withCredential: credential,
465465 isReauthentication: false )
466- decoratedCallback ( authData, nil )
466+ decoratedCallback ( . success ( authData) )
467467 } catch {
468- decoratedCallback ( nil , error)
468+ decoratedCallback ( . failure ( error) )
469469 }
470470 }
471471 }
@@ -544,9 +544,9 @@ extension Auth: AuthInterop {
544544 withCredential: credential,
545545 isReauthentication: false
546546 )
547- decoratedCallback ( authData, nil )
547+ decoratedCallback ( . success ( authData) )
548548 } catch {
549- decoratedCallback ( nil , error)
549+ decoratedCallback ( . failure ( error) )
550550 }
551551 }
552552 }
@@ -642,9 +642,9 @@ extension Auth: AuthInterop {
642642 do {
643643 let authData = try await self . internalSignInAndRetrieveData ( withCredential: credential,
644644 isReauthentication: false )
645- decoratedCallback ( authData, nil )
645+ decoratedCallback ( . success ( authData) )
646646 } catch {
647- decoratedCallback ( nil , error)
647+ decoratedCallback ( . failure ( error) )
648648 }
649649 }
650650 }
@@ -710,7 +710,7 @@ extension Auth: AuthInterop {
710710 let decoratedCallback = self . signInFlowAuthDataResultCallback ( byDecorating: completion)
711711 if let currentUser = self . _currentUser, currentUser. isAnonymous {
712712 let result = AuthDataResult ( withUser: currentUser, additionalUserInfo: nil )
713- decoratedCallback ( result, nil )
713+ decoratedCallback ( . success ( result) )
714714 return
715715 }
716716 let request = SignUpNewUserRequest ( requestConfiguration: self . requestConfiguration)
@@ -728,10 +728,11 @@ extension Auth: AuthInterop {
728728 profile: nil ,
729729 username: nil ,
730730 isNewUser: true )
731- decoratedCallback ( AuthDataResult ( withUser: user, additionalUserInfo: additionalUserInfo) ,
732- nil )
731+ decoratedCallback (
732+ . success( AuthDataResult ( withUser: user, additionalUserInfo: additionalUserInfo) )
733+ )
733734 } catch {
734- decoratedCallback ( nil , error)
735+ decoratedCallback ( . failure ( error) )
735736 }
736737 }
737738 }
@@ -790,10 +791,11 @@ extension Auth: AuthInterop {
790791 profile: nil ,
791792 username: nil ,
792793 isNewUser: response. isNewUser)
793- decoratedCallback ( AuthDataResult ( withUser: user, additionalUserInfo: additionalUserInfo) ,
794- nil )
794+ decoratedCallback (
795+ . success( AuthDataResult ( withUser: user, additionalUserInfo: additionalUserInfo) )
796+ )
795797 } catch {
796- decoratedCallback ( nil , error)
798+ decoratedCallback ( . failure ( error) )
797799 }
798800 }
799801 }
@@ -866,7 +868,7 @@ extension Auth: AuthInterop {
866868 action: AuthRecaptchaAction . signUpPassword) { response, error in
867869 if let error {
868870 DispatchQueue . main. async {
869- decoratedCallback ( nil , error)
871+ decoratedCallback ( . failure ( error) )
870872 }
871873 return
872874 }
@@ -881,7 +883,8 @@ extension Auth: AuthInterop {
881883
882884 func internalCreateUserWithEmail( request: SignUpNewUserRequest ,
883885 inResponse: SignUpNewUserResponse ? = nil ,
884- decoratedCallback: @escaping ( AuthDataResult ? , Error ? ) -> Void ) {
886+ decoratedCallback: @escaping ( Result < AuthDataResult , Error > )
887+ -> Void ) {
885888 Task {
886889 do {
887890 var response : SignUpNewUserResponse
@@ -900,11 +903,11 @@ extension Auth: AuthInterop {
900903 profile: nil ,
901904 username: nil ,
902905 isNewUser: true )
903- decoratedCallback ( AuthDataResult ( withUser : user ,
904- additionalUserInfo: additionalUserInfo) ,
905- nil )
906+ decoratedCallback (
907+ . success ( AuthDataResult ( withUser : user , additionalUserInfo: additionalUserInfo) )
908+ )
906909 } catch {
907- decoratedCallback ( nil , error)
910+ decoratedCallback ( . failure ( error) )
908911 }
909912 }
910913 }
@@ -1009,9 +1012,9 @@ extension Auth: AuthInterop {
10091012 let actionCodeInfo = ActionCodeInfo ( withOperation: operation,
10101013 email: email,
10111014 newEmail: response. verifiedEmail)
1012- Auth . wrapMainAsync ( callback: completion, withParam : actionCodeInfo, error : nil )
1015+ Auth . wrapMainAsync ( callback: completion, with : . success ( actionCodeInfo) )
10131016 } catch {
1014- Auth . wrapMainAsync ( callback: completion, withParam : nil , error: error )
1017+ Auth . wrapMainAsync ( callback: completion, with : . failure ( error) )
10151018 }
10161019 }
10171020 }
@@ -2238,23 +2241,19 @@ extension Auth: AuthInterop {
22382241 /// Invoked asynchronously on the main thread in the future.
22392242 /// - Returns: Returns a block that updates the current user.
22402243 func signInFlowAuthDataResultCallback( byDecorating callback:
2241- ( ( AuthDataResult ? , Error ? ) -> Void ) ? ) -> ( AuthDataResult ? , Error ? ) -> Void {
2242- let authDataCallback : ( ( ( AuthDataResult ? , Error ? ) -> Void ) ? , AuthDataResult ? , Error ? ) -> Void =
2243- { callback, result, error in
2244- Auth . wrapMainAsync ( callback: callback, withParam: result, error: error)
2245- }
2246- return { authResult, error in
2247- if let error {
2248- authDataCallback ( callback, nil , error)
2249- return
2250- }
2251- do {
2252- try self . updateCurrentUser ( authResult? . user, byForce: false , savingToDisk: true )
2253- } catch {
2254- authDataCallback ( callback, nil , error)
2255- return
2244+ ( ( AuthDataResult ? , Error ? ) -> Void ) ? ) -> ( Result < AuthDataResult , Error > ) -> Void {
2245+ return { result in
2246+ switch result {
2247+ case let . success( authResult) :
2248+ do {
2249+ try self . updateCurrentUser ( authResult. user, byForce: false , savingToDisk: true )
2250+ Auth . wrapMainAsync ( callback: callback, with: . success( authResult) )
2251+ } catch {
2252+ Auth . wrapMainAsync ( callback: callback, with: . failure( error) )
2253+ }
2254+ case let . failure( error) :
2255+ Auth . wrapMainAsync ( callback: callback, with: . failure( error) )
22562256 }
2257- authDataCallback ( callback, authResult, nil )
22582257 }
22592258 }
22602259
@@ -2278,11 +2277,12 @@ extension Auth: AuthInterop {
22782277 }
22792278
22802279 class func wrapMainAsync< T: Any > ( callback: ( ( T ? , Error ? ) -> Void ) ? ,
2281- withParam param: T ? ,
2282- error: Error ? ) -> Void {
2283- if let callback {
2284- DispatchQueue . main. async {
2285- callback ( param, error)
2280+ with result: Result < T , Error > ) -> Void {
2281+ guard let callback else { return }
2282+ DispatchQueue . main. async {
2283+ switch result {
2284+ case let . success( success) : callback ( success, nil )
2285+ case let . failure( error) : callback ( nil , error)
22862286 }
22872287 }
22882288 }
0 commit comments