File tree Expand file tree Collapse file tree 7 files changed +29
-67
lines changed
FirebaseAppleSwiftUI/Sources/Services
FirebaseAuthSwiftUI/Sources/Services
FirebaseFacebookSwiftUI/Sources/Services
FirebaseGoogleSwiftUI/Sources/Services
FirebaseOAuthSwiftUI/Sources/Services Expand file tree Collapse file tree 7 files changed +29
-67
lines changed Original file line number Diff line number Diff line change 99import FirebaseAuthSwiftUI
1010import Observation
1111
12- protocol AppleOperationReauthentication {
12+ protocol AppleOperationReauthentication : ProviderOperationReauthentication {
1313 var appleProvider : AppleProviderSwift { get }
1414}
1515
1616extension AppleOperationReauthentication {
17- @MainActor func reauthenticate( ) async throws {
18- guard let user = Auth . auth ( ) . currentUser else {
19- throw AuthServiceError . reauthenticationRequired ( " No user currently signed-in " )
20- }
21-
22- do {
23- let credential = try await appleProvider. createAuthCredential ( )
24- try await user. reauthenticate ( with: credential)
25- } catch {
26- throw AuthServiceError . signInFailed ( underlying: error)
27- }
28- }
17+ var authProvider : AuthProviderSwift { appleProvider }
2918}
3019
3120@MainActor
Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ protocol EmailPasswordOperationReauthentication {
2020}
2121
2222extension EmailPasswordOperationReauthentication {
23- // TODO: - @MainActor because User is non-sendable. Might change this once User is sendable in firebase-ios-sdk
2423 @MainActor func reauthenticate( ) async throws {
2524 guard let user = Auth . auth ( ) . currentUser else {
2625 throw AuthServiceError . reauthenticationRequired ( " No user currently signed-in " )
Original file line number Diff line number Diff line change @@ -45,3 +45,22 @@ public extension AuthenticatedOperation {
4545 }
4646 }
4747}
48+
49+ public protocol ProviderOperationReauthentication {
50+ var authProvider : AuthProviderSwift { get }
51+ }
52+
53+ public extension ProviderOperationReauthentication {
54+ @MainActor func reauthenticate( ) async throws {
55+ guard let user = Auth . auth ( ) . currentUser else {
56+ throw AuthServiceError . reauthenticationRequired ( " No user currently signed-in " )
57+ }
58+
59+ do {
60+ let credential = try await authProvider. createAuthCredential ( )
61+ try await user. reauthenticate ( with: credential)
62+ } catch {
63+ throw AuthServiceError . signInFailed ( underlying: error)
64+ }
65+ }
66+ }
Original file line number Diff line number Diff line change 2323import FirebaseAuthSwiftUI
2424import Observation
2525
26- protocol FacebookOperationReauthentication {
26+ protocol FacebookOperationReauthentication : ProviderOperationReauthentication {
2727 var facebookProvider : FacebookProviderSwift { get }
2828}
2929
3030extension FacebookOperationReauthentication {
31- @MainActor func reauthenticate( ) async throws {
32- guard let user = Auth . auth ( ) . currentUser else {
33- throw AuthServiceError . reauthenticationRequired ( " No user currently signed-in " )
34- }
35-
36- do {
37- let credential = try await facebookProvider. createAuthCredential ( )
38- try await user. reauthenticate ( with: credential)
39- } catch {
40- throw AuthServiceError . signInFailed ( underlying: error)
41- }
42- }
31+ var authProvider : AuthProviderSwift { facebookProvider }
4332}
4433
4534@MainActor
Original file line number Diff line number Diff line change 3030import FirebaseAuthSwiftUI
3131import Observation
3232
33- protocol GoogleOperationReauthentication {
33+ protocol GoogleOperationReauthentication : ProviderOperationReauthentication {
3434 var googleProvider : GoogleProviderSwift { get }
3535}
3636
3737extension GoogleOperationReauthentication {
38- @MainActor func reauthenticate( ) async throws {
39- guard let user = Auth . auth ( ) . currentUser else {
40- throw AuthServiceError . reauthenticationRequired ( " No user currently signed-in " )
41- }
42-
43- do {
44- let credential = try await googleProvider. createAuthCredential ( )
45- try await user. reauthenticate ( with: credential)
46-
47- } catch {
48- throw AuthServiceError . signInFailed ( underlying: error)
49- }
50- }
38+ var authProvider : AuthProviderSwift { googleProvider }
5139}
5240
5341@MainActor
Original file line number Diff line number Diff line change 99import FirebaseAuthSwiftUI
1010import Observation
1111
12- protocol OAuthOperationReauthentication {
12+ protocol OAuthOperationReauthentication : ProviderOperationReauthentication {
1313 var oauthProvider : OAuthProviderSwift { get }
1414}
1515
1616extension OAuthOperationReauthentication {
17- @MainActor func reauthenticate( ) async throws {
18- guard let user = Auth . auth ( ) . currentUser else {
19- throw AuthServiceError . reauthenticationRequired ( " No user currently signed-in " )
20- }
21-
22- do {
23- let credential = try await oauthProvider. createAuthCredential ( )
24- try await user. reauthenticate ( with: credential)
25- } catch {
26- throw AuthServiceError . signInFailed ( underlying: error)
27- }
28- }
17+ var authProvider : AuthProviderSwift { oauthProvider }
2918}
3019
3120@MainActor
Original file line number Diff line number Diff line change 99import FirebaseAuthSwiftUI
1010import Observation
1111
12- protocol TwitterOperationReauthentication {
12+ protocol TwitterOperationReauthentication : ProviderOperationReauthentication {
1313 var twitterProvider : TwitterProviderSwift { get }
1414}
1515
1616extension TwitterOperationReauthentication {
17- @MainActor func reauthenticate( ) async throws {
18- guard let user = Auth . auth ( ) . currentUser else {
19- throw AuthServiceError . reauthenticationRequired ( " No user currently signed-in " )
20- }
21-
22- do {
23- let credential = try await twitterProvider. createAuthCredential ( )
24- try await user. reauthenticate ( with: credential)
25- } catch {
26- throw AuthServiceError . signInFailed ( underlying: error)
27- }
28- }
17+ var authProvider : AuthProviderSwift { twitterProvider }
2918}
3019
3120@MainActor
You can’t perform that action at this time.
0 commit comments