简体   繁体   中英

Google gapi.auth2.getAuthInstance().isSignedIn().get() is always false when multiple google accounts

I am having a weird problem with google gapi auth. For some reason, the value for gapi.auth2.getAuthInstance().isSignedIn().get() is always returning false. This is my setup:

gapi.load("auth2", initAuth2);

initAuth2(){
    gapi.auth2.init({
      client_id: "xxxxx-yyyyy.apps.googleusercontent.com",
      hosted_domain: "domain.com",
      redirect_uri: "http://localhost:4200",
      ux_mode: "redirect",
    }).then(performAuth, error=>{
      console.error(`Error initiating gapi auth2: ${error.details}`);
    });
}

performAuth(googleAuth){
    const isSignedIn = googleAuth.isSignedIn.get();
    if(!isSignedIn){
      googleAuth.signIn();
      return;
    }
    const user = googleAuth.currentUser.get();
    console.log(user);
}

I have two google workspace accounts sign in the same chrome profile. When I run this script, I get the prompt to select an account. No matter which one I choose, the flow just keeps looping. The reason for that is that the line const isSignedIn = googleAuth.isSignedIn.get(); is always returning false.

Things I've tried so far:

  1. I thought that maybe the client_id was corrupted so I generated a new one. Same behaviour.
  2. I though the GCP project was corrupted, so I created a new project with new credentials. Same behaviour.
  3. Thought there was an issue with cookies, so I deleted and clear cookies and history. Same behaviour.
  4. Thought is was related only to localhost so I deployed to the web. Same behaviour.

If I change the init options from ux_mode: "redirect" to ux_mode: "prompt" . It works. However, that is not the desired experience. Also, if I only have one google workspace in the chrome profile, it works. Even more interesting... if I use a client id from an older project... it works. The problem is that the consent screen shows the wrong app name.

I know this question is similar to this one , however I feel it's different because none of the above troubleshooting works. Any insights?

There is a case for the exact same problem here , it is most likely a bug in the api set

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM