'New Google Sign In library prompt at every page reload

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 ?



Solution 1:[1]

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

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex
Solution 2 Nitin Bhojwani