4

In my project, I use regular popup client-sided JS authentication (platform client)

I migrated from old Google Sign in to new Google Identity Platform (gsi client)

I used the simple exemple code

window.onload = function () {
  google.accounts.id.initialize({
    client_id: 'YOUR_GOOGLE_CLIENT_ID',
    callback: handleCredentialResponse,
    auto_select: true
  });
  google.accounts.id.prompt();
}

My problem is, each time a user reload the page, he gets the One Tap UX prompt which take tremendous time

A second problem to that is if a user have 2 Google account connected to his browser, the prompt ask him to choose the account everytime he reloads (like it's not saved)

How can I achieve the behavior I had with the last library which is too simply have nothing changed at page reload but only when connecting the first time ?

Plotisateur
  • 476
  • 9
  • 23
  • It would be very useful for the community if you could provide any feedback on my answer, please? – Alex Mar 25 '22 at 15:52
  • As to 2 accounts: In my experience, if user does sign out from the app (using a call to google.accounts.id.revoke) under one account, this account will no longer be suggested in One Tap. – Yaegor Jun 30 '22 at 13:06
  • A related question with details: https://stackoverflow.com/questions/72816068/how-to-make-new-sign-in-with-google-button-preserve-user-signed-in-state-on-page (but still no answer on how to get rid of the one tap sign-in delay) – Yaegor Aug 24 '22 at 12:25

2 Answers2

1

I think Automatic sign-in is what you need.

Google One Tap supports automatic sign-in, which provides a frictionless user experience (UX) by removing the manual steps visitors must take when returning to your site. Users don't need to remember which Google Account they selected during their last visit, decreasing the chances of unnecessary duplicate accounts being created on your platform.

Automatic sign-in is intended to complement our Sign In With Google button and One Tap dialogs. It is designed to be used across your entire site, with manual sign-up or switching accounts occurring only after the user has first signed-out of your site.

To enable automatic sign-in, add data-auto_select="true" to your HTML code, as shown in the following snippet:

<div id="g_id_onload"
     data-client_id="YOUR_GOOGLE_CLIENT_ID"
     data-auto_select="true"
     data-login_uri="https://your.domain/your_login_endpoint">
</div>

Refer: https://developers.google.com/identity/gsi/web/guides/automatic-sign-in-sign-out#sign-in-users-automatically

Nitin Bhojwani
  • 702
  • 1
  • 5
  • 14
  • 2
    As you can see in my exemple, I already use Auto Sign In – Plotisateur Mar 21 '22 at 11:20
  • Is it happening when there are multiple Google account sign-ins in the same browser? https://stackoverflow.com/a/68783616/4184976 – Nitin Bhojwani Mar 21 '22 at 12:27
  • Yes I know they have to choose an account first, but I believed it would be known to the GSign cookie that my page then auto sign with the chosen account. Actually it asks to choose between accounts everytime and I can't see myself ask to my user to "log into one account only" – Plotisateur Mar 21 '22 at 14:08
0

After some research it was determined that this issue might be caused by callback function that handles an ID token. I would like to add that your Singing method is correct and other users also do it this way as seen here. I think you should take a look at the Authenticate with a backend server guide to know how to handle these tokens, .

Alex
  • 778
  • 1
  • 15
  • Have you tried authenticating with the [backend](https://developers.google.com/identity/sign-in/web/backend-auth#using-a-google-api-client-library) ? – Alex Mar 31 '22 at 19:08
  • 1
    Alex, you seem to link to the old library, not the new one. New one also has "redirect" flow, but I assume Plotisateur needs the one without redirect which worked perfectly with the old library. – Yaegor Jun 30 '22 at 13:00