Skip to content

Commit 37a1bd3

Browse files
chore: update types
1 parent f5bef03 commit 37a1bd3

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/FirebaseAuthSwiftUI/FirebaseAuthSwiftUI.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ protocol AuthListenerProtocol {
1111
func onSignedIn(_ user: User)
1212
func onCanceled()
1313
// TODO - add when I get to this point
14-
// func onCredentialReceived(_ credential: AuthCredential)
15-
// func onCredentialLinked(_ credential: AuthCredential)
14+
func onCredentialReceived(_ credential: AuthCredential)
15+
func onCredentialLinked(_ credential: AuthCredential)
1616
// func onMFARequired(_ resolver: MultiFactorResolver)
1717
}
1818

@@ -43,16 +43,21 @@ enum AuthAction {
4343
case none
4444
}
4545

46-
class AuthProvider<Listener: AuthListenerProtocol, Credential: AuthCredential>: AuthProviderProtocol {
46+
class AuthProvider<Listener: AuthListenerProtocol>: AuthProviderProtocol {
4747
var auth: Auth = Auth.auth()
4848
var authListener: Listener
4949
var providerId: String
5050

51-
init(listener: Listener) {
51+
init(listener: Listener, providerId: String) {
5252
self.authListener = listener
53+
self.providerId = providerId
5354
}
55+
56+
var shouldUpgradeAnonymous: Bool {
57+
return Auth.auth().currentUser?.isAnonymous ?? false
58+
}
5459

55-
func signInWithCredential(_ credential: Credential) {
60+
func signInWithCredential(_ credential: AuthCredential) {
5661
authListener.onBeforeSignIn()
5762
auth.signIn(with: credential) { [weak self] result, error in
5863
if let error = error {
@@ -63,7 +68,7 @@ class AuthProvider<Listener: AuthListenerProtocol, Credential: AuthCredential>:
6368
}
6469
}
6570

66-
func linkWithCredential(_ credential: Credential) {
71+
func linkWithCredential(_ credential: AuthCredential) {
6772
authListener.onCredentialReceived(credential)
6873
guard let user = auth.currentUser else { return }
6974

@@ -79,17 +84,17 @@ class AuthProvider<Listener: AuthListenerProtocol, Credential: AuthCredential>:
7984
func onCredentialReceived(credential: AuthCredential, action: AuthAction) {
8085
switch action {
8186
case .link:
82-
linkWithCredential(credential: credential)
87+
linkWithCredential(credential)
8388
case .signIn, .signUp:
8489
// Only email provider has a different action for sign in and sign up
8590
// and implements its own sign up logic.
8691
if shouldUpgradeAnonymous {
87-
linkWithCredential(credential: credential)
92+
linkWithCredential(credential)
8893
} else {
89-
signInWithCredential(credential: credential)
94+
signInWithCredential(credential)
9095
}
9196
case .none:
92-
authListener.onCredentialReceived(credential: credential)
97+
authListener.onCredentialReceived(credential)
9398
}
9499
}
95100
// TODO - fetchSignInMethodsForEmail/fetchProvidersForEmail is deprecated

0 commit comments

Comments
 (0)