search

Home  >  Q&A  >  body text

How do I verify that a user is signed in to their Google Account using Google One Tap?

My question is here (How to check if the user is logged in using "Google Sign In" (OAuth 2.0)), but the related package is deprecated (https://developers.google.com/identity/login/network /personnel).

I use Google One Tap in my project. How do I know if a user is signed in to their Google Account using Google One Tap.

P粉736935587P粉736935587241 days ago370

reply all(1)I'll reply

  • P粉805535434

    P粉8055354342024-03-28 11:00:03

    I asked Google Bard and I think it gives a good answer.

    There are several ways to check if a user is logged in to Google.

    • Check the user's session storage. If the user is logged in, the user's session store will contain the user's Google ID key. You can check this key to know if the user is logged in. < /里>
    • Use Google Sign In API. The Google Sign In API provides a way to check if the user is logged in. You can use this API to get a user's Google ID and other information about their identity account.
    • Check the user's browser cookies. If the user is logged in, the user's browser cookie will contain cookies for the Google login service. You can check this cookie to see if the user is logged in.

    Here's an example of how to check if a user is logged in using the Google Sign In API:

    const googleSignIn = require('google-signin');
    
    const auth2 = googleSignIn.build();
    
    const isSignedIn = await auth2.isSignedIn();
    
    if (isSignedIn) {
      // The user is logged in.
      const user = await auth2.currentUser();
    
      // Do something with the user's information.
    } else {
      // The user is not logged in.
    }

    Use Google One-Click Package:

    const googleOneTap = require('google-one-tap');
    
    const auth2 = googleOneTap.build();
    
    const isSignedIn = await auth2.isSignedIn();
    
    if (isSignedIn) {
      // The user is logged in.
      const user = await auth2.currentUser();
    
      // Do something with the user's information.
    } else {
      // The user is not logged in.
    }

    In addition, you can also access other user information through these two packages. If you need a different solution, you can use Google Bard.

    reply
    0
  • Cancelreply