Skip to content

Commit 1f71d23

Browse files
committed
Improved error detection reliability
1 parent b956e76 commit 1f71d23

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/Firebase.Auth/FirebaseAuthProvider.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ public async Task<FirebaseAuthLink> SignInWithGoogleIdTokenAsync(string idToken)
132132
var content = $"{{\"postBody\":\"id_token={idToken}&providerId={providerId}\",\"requestUri\":\"http://localhost\",\"returnSecureToken\":true}}";
133133

134134
return await this.ExecuteWithPostContentAsync(GoogleIdentityUrl, content).ConfigureAwait(false);
135-
}
135+
}
136136

137-
/// <summary>
138-
/// Sign in user anonymously. He would still have a user id and access token generated, but name and other personal user properties will be null.
139-
/// </summary>
140-
/// <returns> The <see cref="FirebaseAuth"/>. </returns>
141-
public async Task<FirebaseAuthLink> SignInAnonymouslyAsync()
137+
/// <summary>
138+
/// Sign in user anonymously. He would still have a user id and access token generated, but name and other personal user properties will be null.
139+
/// </summary>
140+
/// <returns> The <see cref="FirebaseAuth"/>. </returns>
141+
public async Task<FirebaseAuthLink> SignInAnonymouslyAsync()
142142
{
143143
var content = $"{{\"returnSecureToken\":true}}";
144144

@@ -543,9 +543,6 @@ private static AuthErrorReason GetFailureReason(string responseData)
543543
break;
544544

545545
//possible errors from Email/Password Account Signup (via signupNewUser or setAccountInfo)
546-
case "WEAK_PASSWORD : Password should be at least 6 characters":
547-
failureReason = AuthErrorReason.WeakPassword;
548-
break;
549546
case "EMAIL_EXISTS":
550547
failureReason = AuthErrorReason.EmailExists;
551548
break;
@@ -565,9 +562,6 @@ private static AuthErrorReason GetFailureReason(string responseData)
565562
case "USER_DISABLED":
566563
failureReason = AuthErrorReason.UserDisabled;
567564
break;
568-
case "TOO_MANY_ATTEMPTS_TRY_LATER":
569-
failureReason = AuthErrorReason.TooManyAttemptsTryLater;
570-
break;
571565

572566
//possible errors from Email/Password Signin or Password Recovery or Email/Password Sign up using setAccountInfo
573567
case "MISSING_EMAIL":
@@ -598,6 +592,14 @@ private static AuthErrorReason GetFailureReason(string responseData)
598592
failureReason = AuthErrorReason.AlreadyLinked;
599593
break;
600594
}
595+
596+
if(failureReason == AuthErrorReason.Undefined)
597+
{
598+
//possible errors from Email/Password Account Signup (via signupNewUser or setAccountInfo)
599+
if(errorData?.error?.message?.StartsWith("WEAK_PASSWORD :") ?? false) failureReason = AuthErrorReason.WeakPassword;
600+
//possible errors from Email/Password Signin
601+
else if (errorData?.error?.message?.StartsWith("TOO_MANY_ATTEMPTS_TRY_LATER :") ?? false) failureReason = AuthErrorReason.TooManyAttemptsTryLater;
602+
}
601603
}
602604
}
603605
catch (JsonReaderException)

0 commit comments

Comments
 (0)