google-signin icon indicating copy to clipboard operation
google-signin copied to clipboard

RNGoogleSignInError: Unknown error when signing in., Error Domain=com.google.GIDSignIn Code=-8

Open samkit-jain opened this issue 2 years ago • 7 comments

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,

samkit-jain avatar Jun 08 '22 15:06 samkit-jain

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 🙂

vonovak avatar Jun 11 '22 05:06 vonovak

same error =(

medarzr avatar Jun 28 '22 06:06 medarzr

same error .....

marquina-abreu avatar Jan 27 '23 20:01 marquina-abreu

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"; }

stachu2k avatar Apr 11 '23 10:04 stachu2k

I have a similar error:

[Error: RNGoogleSignInError: Unknown error when signing in., Error Domain=com.google.GIDSignIn Code=-7 "(null)"

osvald0 avatar Apr 17 '23 19:04 osvald0

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 avatar Jun 02 '23 08:06 ravis-farooq

@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.

stachu2k avatar Jun 06 '23 14:06 stachu2k