@@ -109,8 +109,12 @@ abstract class AuthProvider<T extends AuthListener, K extends AuthCredential> {
109
109
/// {@macro ui.auth.auth_provider}
110
110
AuthProvider ();
111
111
112
+ /// Indicates whether the user should be upgraded and new credential should be
113
+ /// linked.
114
+ bool get shouldUpgradeAnonymous => auth.currentUser? .isAnonymous ?? false ;
115
+
112
116
/// Signs the user in with the provided [AuthCredential] .
113
- void signInWithCredential (AuthCredential credential) {
117
+ void signInWithCredential (K credential) {
114
118
authListener.onBeforeSignIn ();
115
119
auth
116
120
.signInWithCredential (credential)
@@ -120,8 +124,9 @@ abstract class AuthProvider<T extends AuthListener, K extends AuthCredential> {
120
124
121
125
/// Links a provided [AuthCredential] with the currently signed in user
122
126
/// account.
123
- void linkWithCredential (AuthCredential credential) {
127
+ void linkWithCredential (K credential) {
124
128
authListener.onCredentialReceived (credential);
129
+
125
130
try {
126
131
final user = auth.currentUser! ;
127
132
user
@@ -175,6 +180,11 @@ abstract class AuthProvider<T extends AuthListener, K extends AuthCredential> {
175
180
// Only email provider has a different action for sign in and sign up
176
181
// and implements it's own sign up logic.
177
182
case AuthAction .signUp:
183
+ if (shouldUpgradeAnonymous) {
184
+ linkWithCredential (credential);
185
+ break ;
186
+ }
187
+
178
188
signInWithCredential (credential);
179
189
break ;
180
190
case AuthAction .none:
0 commit comments