@@ -11,8 +11,8 @@ protocol AuthListenerProtocol {
11
11
func onSignedIn( _ user: User )
12
12
func onCanceled( )
13
13
// 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 )
16
16
// func onMFARequired(_ resolver: MultiFactorResolver)
17
17
}
18
18
@@ -43,16 +43,21 @@ enum AuthAction {
43
43
case none
44
44
}
45
45
46
- class AuthProvider < Listener: AuthListenerProtocol , Credential : AuthCredential > : AuthProviderProtocol {
46
+ class AuthProvider < Listener: AuthListenerProtocol > : AuthProviderProtocol {
47
47
var auth : Auth = Auth . auth ( )
48
48
var authListener : Listener
49
49
var providerId : String
50
50
51
- init ( listener: Listener ) {
51
+ init ( listener: Listener , providerId : String ) {
52
52
self . authListener = listener
53
+ self . providerId = providerId
53
54
}
55
+
56
+ var shouldUpgradeAnonymous : Bool {
57
+ return Auth . auth ( ) . currentUser? . isAnonymous ?? false
58
+ }
54
59
55
- func signInWithCredential( _ credential: Credential ) {
60
+ func signInWithCredential( _ credential: AuthCredential ) {
56
61
authListener. onBeforeSignIn ( )
57
62
auth. signIn ( with: credential) { [ weak self] result, error in
58
63
if let error = error {
@@ -63,7 +68,7 @@ class AuthProvider<Listener: AuthListenerProtocol, Credential: AuthCredential>:
63
68
}
64
69
}
65
70
66
- func linkWithCredential( _ credential: Credential ) {
71
+ func linkWithCredential( _ credential: AuthCredential ) {
67
72
authListener. onCredentialReceived ( credential)
68
73
guard let user = auth. currentUser else { return }
69
74
@@ -79,17 +84,17 @@ class AuthProvider<Listener: AuthListenerProtocol, Credential: AuthCredential>:
79
84
func onCredentialReceived( credential: AuthCredential , action: AuthAction ) {
80
85
switch action {
81
86
case . link:
82
- linkWithCredential ( credential: credential )
87
+ linkWithCredential ( credential)
83
88
case . signIn, . signUp:
84
89
// Only email provider has a different action for sign in and sign up
85
90
// and implements its own sign up logic.
86
91
if shouldUpgradeAnonymous {
87
- linkWithCredential ( credential: credential )
92
+ linkWithCredential ( credential)
88
93
} else {
89
- signInWithCredential ( credential: credential )
94
+ signInWithCredential ( credential)
90
95
}
91
96
case . none:
92
- authListener. onCredentialReceived ( credential: credential )
97
+ authListener. onCredentialReceived ( credential)
93
98
}
94
99
}
95
100
// TODO - fetchSignInMethodsForEmail/fetchProvidersForEmail is deprecated
0 commit comments