Skip to content

Commit

Permalink
fix(android,auth): return correct error code for linkWithCredential `…
Browse files Browse the repository at this point in the history
…provider-already-linked` on Android (#8245)
  • Loading branch information
pr-Mais committed Mar 10, 2022
1 parent 32d06e7 commit ae09071
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,21 @@ private Task<Map<String, Object>> linkUserWithCredential(Map<String, Object> arg
throw FlutterFirebaseAuthPluginException.invalidCredential();
}

AuthResult authResult = Tasks.await(firebaseUser.linkWithCredential(credential));
AuthResult authResult;

try {
authResult = Tasks.await(firebaseUser.linkWithCredential(credential));
} catch (Exception exception) {
String message = exception.getMessage();

if (message != null
&& message.contains("User has already been linked to the given provider.")) {
throw FlutterFirebaseAuthPluginException.alreadyLinkedProvider();
}

throw exception;
}

return parseAuthResult(authResult);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ static FlutterFirebaseAuthPluginException noSuchProvider() {
"NO_SUCH_PROVIDER", "User was not linked to an account with the given provider.");
}

static FlutterFirebaseAuthPluginException alreadyLinkedProvider() {
return new FlutterFirebaseAuthPluginException(
"PROVIDER_ALREADY_LINKED", "User has already been linked to the given provider.");
}

public String getCode() {
return code.toLowerCase(Locale.ROOT).replace("error_", "").replace("_", "-");
}
Expand Down

0 comments on commit ae09071

Please sign in to comment.