@@ -300,9 +300,9 @@ extension Auth: AuthInterop {
300
300
Task {
301
301
do {
302
302
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) )
304
304
} catch {
305
- Auth . wrapMainAsync ( callback: completion, withParam : nil , error: error )
305
+ Auth . wrapMainAsync ( callback: completion, with : . failure ( error) )
306
306
}
307
307
}
308
308
}
@@ -365,9 +365,9 @@ extension Auth: AuthInterop {
365
365
withEmail: email,
366
366
password: password
367
367
)
368
- decoratedCallback ( authData, nil )
368
+ decoratedCallback ( . success ( authData) )
369
369
} catch {
370
- decoratedCallback ( nil , error)
370
+ decoratedCallback ( . failure ( error) )
371
371
}
372
372
}
373
373
}
@@ -463,9 +463,9 @@ extension Auth: AuthInterop {
463
463
do {
464
464
let authData = try await self . internalSignInAndRetrieveData ( withCredential: credential,
465
465
isReauthentication: false )
466
- decoratedCallback ( authData, nil )
466
+ decoratedCallback ( . success ( authData) )
467
467
} catch {
468
- decoratedCallback ( nil , error)
468
+ decoratedCallback ( . failure ( error) )
469
469
}
470
470
}
471
471
}
@@ -544,9 +544,9 @@ extension Auth: AuthInterop {
544
544
withCredential: credential,
545
545
isReauthentication: false
546
546
)
547
- decoratedCallback ( authData, nil )
547
+ decoratedCallback ( . success ( authData) )
548
548
} catch {
549
- decoratedCallback ( nil , error)
549
+ decoratedCallback ( . failure ( error) )
550
550
}
551
551
}
552
552
}
@@ -642,9 +642,9 @@ extension Auth: AuthInterop {
642
642
do {
643
643
let authData = try await self . internalSignInAndRetrieveData ( withCredential: credential,
644
644
isReauthentication: false )
645
- decoratedCallback ( authData, nil )
645
+ decoratedCallback ( . success ( authData) )
646
646
} catch {
647
- decoratedCallback ( nil , error)
647
+ decoratedCallback ( . failure ( error) )
648
648
}
649
649
}
650
650
}
@@ -710,7 +710,7 @@ extension Auth: AuthInterop {
710
710
let decoratedCallback = self . signInFlowAuthDataResultCallback ( byDecorating: completion)
711
711
if let currentUser = self . _currentUser, currentUser. isAnonymous {
712
712
let result = AuthDataResult ( withUser: currentUser, additionalUserInfo: nil )
713
- decoratedCallback ( result, nil )
713
+ decoratedCallback ( . success ( result) )
714
714
return
715
715
}
716
716
let request = SignUpNewUserRequest ( requestConfiguration: self . requestConfiguration)
@@ -728,10 +728,11 @@ extension Auth: AuthInterop {
728
728
profile: nil ,
729
729
username: nil ,
730
730
isNewUser: true )
731
- decoratedCallback ( AuthDataResult ( withUser: user, additionalUserInfo: additionalUserInfo) ,
732
- nil )
731
+ decoratedCallback (
732
+ . success( AuthDataResult ( withUser: user, additionalUserInfo: additionalUserInfo) )
733
+ )
733
734
} catch {
734
- decoratedCallback ( nil , error)
735
+ decoratedCallback ( . failure ( error) )
735
736
}
736
737
}
737
738
}
@@ -790,10 +791,11 @@ extension Auth: AuthInterop {
790
791
profile: nil ,
791
792
username: nil ,
792
793
isNewUser: response. isNewUser)
793
- decoratedCallback ( AuthDataResult ( withUser: user, additionalUserInfo: additionalUserInfo) ,
794
- nil )
794
+ decoratedCallback (
795
+ . success( AuthDataResult ( withUser: user, additionalUserInfo: additionalUserInfo) )
796
+ )
795
797
} catch {
796
- decoratedCallback ( nil , error)
798
+ decoratedCallback ( . failure ( error) )
797
799
}
798
800
}
799
801
}
@@ -866,7 +868,7 @@ extension Auth: AuthInterop {
866
868
action: AuthRecaptchaAction . signUpPassword) { response, error in
867
869
if let error {
868
870
DispatchQueue . main. async {
869
- decoratedCallback ( nil , error)
871
+ decoratedCallback ( . failure ( error) )
870
872
}
871
873
return
872
874
}
@@ -881,7 +883,8 @@ extension Auth: AuthInterop {
881
883
882
884
func internalCreateUserWithEmail( request: SignUpNewUserRequest ,
883
885
inResponse: SignUpNewUserResponse ? = nil ,
884
- decoratedCallback: @escaping ( AuthDataResult ? , Error ? ) -> Void ) {
886
+ decoratedCallback: @escaping ( Result < AuthDataResult , Error > )
887
+ -> Void ) {
885
888
Task {
886
889
do {
887
890
var response : SignUpNewUserResponse
@@ -900,11 +903,11 @@ extension Auth: AuthInterop {
900
903
profile: nil ,
901
904
username: nil ,
902
905
isNewUser: true )
903
- decoratedCallback ( AuthDataResult ( withUser : user ,
904
- additionalUserInfo: additionalUserInfo) ,
905
- nil )
906
+ decoratedCallback (
907
+ . success ( AuthDataResult ( withUser : user , additionalUserInfo: additionalUserInfo) )
908
+ )
906
909
} catch {
907
- decoratedCallback ( nil , error)
910
+ decoratedCallback ( . failure ( error) )
908
911
}
909
912
}
910
913
}
@@ -1009,9 +1012,9 @@ extension Auth: AuthInterop {
1009
1012
let actionCodeInfo = ActionCodeInfo ( withOperation: operation,
1010
1013
email: email,
1011
1014
newEmail: response. verifiedEmail)
1012
- Auth . wrapMainAsync ( callback: completion, withParam : actionCodeInfo, error : nil )
1015
+ Auth . wrapMainAsync ( callback: completion, with : . success ( actionCodeInfo) )
1013
1016
} catch {
1014
- Auth . wrapMainAsync ( callback: completion, withParam : nil , error: error )
1017
+ Auth . wrapMainAsync ( callback: completion, with : . failure ( error) )
1015
1018
}
1016
1019
}
1017
1020
}
@@ -2238,23 +2241,19 @@ extension Auth: AuthInterop {
2238
2241
/// Invoked asynchronously on the main thread in the future.
2239
2242
/// - Returns: Returns a block that updates the current user.
2240
2243
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) )
2256
2256
}
2257
- authDataCallback ( callback, authResult, nil )
2258
2257
}
2259
2258
}
2260
2259
@@ -2278,11 +2277,12 @@ extension Auth: AuthInterop {
2278
2277
}
2279
2278
2280
2279
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)
2286
2286
}
2287
2287
}
2288
2288
}
0 commit comments