google-signin
google-signin copied to clipboard
RNGoogleSignInError: Unknown error when signing in., Error Domain=com.google.GIDSignIn Code=-8
On iOS, to get access to scopes, one has to use the addScopes
function. This works fine when a user is granting access for the first time. However, when they try to login into the same app, the addScopes
function fails with
RNGoogleSignInError: Unknown error when signing in., Error Domain=com.google.GIDSignIn Code=-8
As per the Google's documentation, this means that the permissions were already given to the user and you do not need to call the addScopes
function again. This can be resolved by passing only those scopes that have not already been granted like
const userObj = await GoogleSignin.signIn();
const userScopes = userObj['scopes'];
let scopesToBeAdded = [];
const SCOPES_REQUIRED = []; // Will contain all the scopes that are required.
for (let i = 0; i < SCOPES_REQUIRED.length; i++) {
if (!userScopes.includes(SCOPES_REQUIRED[i])) {
scopesToBeAdded.push(SCOPES_REQUIRED[i]);
}
}
if (scopesToBeAdded.length > 0) {
const userObj = await GoogleSignin.addScopes({scopes: scopesToBeAdded});
}
What's the reason that the addScopes
fails if the scopes are already granted? Can we make it not fail or just treat it as a warning?
Is this something that can be added into the code itself? If so, I can raise a PR for the same. If not,
Hello and thanks for reporting,
What's the reason that the addScopes fails if the scopes are already granted? Can we make it not fail or just treat it as a warning?
I'm afraid that it a question for the authors of the api, which is google. You can try asking in here https://github.com/googlesamples/google-services. What we could do is expose a slightly nicer way to detect the error so that you don't have to rely on weird error codes (-8). I'm going to keep this open as a reminder.
Can we make it not fail or just treat it as a warning?
you can read the code
property of the error and catch it in a try-catch block.
Thank you 🙂
same error =(
same error .....
Similar error here, but code -10 RNGoogleSignInError: Unknown error when signing in., Error Domain=org.openid.appauth.oauth_token Code=-10 "invalid_grant: Bad Request" UserInfo={OIDOAuthErrorResponseErrorKey={ error = "invalid_grant"; "error_description" = "Bad Request"; }
I have a similar error:
[Error: RNGoogleSignInError: Unknown error when signing in., Error Domain=com.google.GIDSignIn Code=-7 "(null)"
Similar error here, but code -10
RNGoogleSignInError: Unknown error when signing in., Error Domain=org.openid.appauth.oauth_token Code=-10 "invalid_grant: Bad Request" UserInfo={OIDOAuthErrorResponseErrorKey={ error = "invalid_grant"; "error_description" = "Bad Request"; }
Did you fixed that error ?
@ravis-farooq It turned out to be revoked access made by user on his Google account. I modified my code to log out the user and ignore this error.