11

I am trying to make the new google one tap sign in work following this guide:

https://developers.google.com/identity/one-tap/web

google.accounts.id.initialize({
            client_id: '123123123123123123.apps.googleusercontent.com',
            cancel_on_tap_outside: false,
            callback: handleCredentialResponse
        });

        //google.accounts.id.prompt(true);

        google.accounts.id.prompt((notification) => {
            if (notification.isNotDisplayed() || notification.isSkippedMoment()) {

                // continue with another identity provider.
            }
    });

I am using the One Tap JavaScript API to display One Tap. And it perfectly does what it needs to do.

Client side verification and all works well but I've got one problem. After I close the UI by clicking the close button at the top right corner of the window, the UI is not displayed anymore and when I examine the notification status it shows me this error;

opt_out_or_no_session

What do I need to do to keep the UI displayed even if it's closed by the user? I appreciate any help.

Yavuz Asmalı
  • 278
  • 1
  • 3
  • 11
  • The problem seems to be a normal behaviour. There was clearly a section about this topic in the guides page of the API. (See: https://developers.google.com/identity/one-tap/web/guides/features) – Yavuz Asmalı Jun 10 '20 at 08:31
  • I had to do a complete clear of my cache - full details on https://stackoverflow.com/questions/62903602/testing-google-one-tap-closed-and-now-getting-suppressed-by-user-message – maudulus Jul 14 '20 at 21:16

4 Answers4

15

In development, I was able to reset the exponential cool down by removing the g_state cookie.

One method for this might be to add a development-only "Clear Google One Tap Cookie" link that run an server-side action to remove the g_state cookie and then redirect back to the previous page.

Dr Nic
  • 2,072
  • 1
  • 15
  • 19
  • 2
    As the g_state cookie doesn't have the HttpOnly flag you should be able to delete it with javascript in the browser. – user2677034 Apr 29 '22 at 19:43
  • I think this is no longer accurate. The g_state cookie isn't there anymore and i cant figure out how to turn off the cooldown time while in development – Beikeni Aug 02 '23 at 14:47
12
google.accounts.id.prompt((notification) => {
            if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
                document.cookie =  `g_state=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT`;
                google.accounts.id.prompt()
            }
        });

this worked for me to delete the cookie and try again

Diego Rivera
  • 121
  • 1
  • 4
6

This is the so-called "Exponential Cool Down" feature. More details at https://developers.google.com/identity/one-tap/web/guides/features#exponential_cool_down.

Google One Tap is an optimized UX for users to sign-in or sign-up with just one tap. If a user doesn't want to sign-in/sign-up (by closing the One Tap), it should not be displayed again and again on each page reloading or navigation. To most users, it's an annoying UX. With the cool down feature, users won't feel to be pushed to sign-in/sign-up.

Guibin
  • 734
  • 3
  • 5
  • 3
    Ok but what if I'm still in the development process, the UI showed once, I clicked outside and that's just it, I can't do anything until it shows again.. – Omar Tarek Jul 02 '20 at 12:26
  • You can use incognito mode during development. When cooldown triggered, you can restart the incognito window and start over. – Guibin Jul 08 '20 at 17:25
  • 1
    For some reason it didn't work in incognito mode for me, but I found out that if I cleared the cookies for my development site, the cooldown resets, not sure if this is the proper way of explaining/doing it but hey it works. – Omar Tarek Jul 09 '20 at 08:38
  • @Guibin what's the difference between opt_out_or_no_session and suppressed_by_user? This other answer says that suppressed_by_user also means the cooldown period is active - https://stackoverflow.com/questions/61182501/what-does-suppressed-by-user-mean-when-using-google-one-tap The One Tap docs have no detail on these codes - https://developers.google.com/identity/one-tap/web/reference/js-reference#PromptMomentNotification – monkeyboy Jul 13 '20 at 15:25
1

Individual user accounts may globally opt-out of using One Tap from their Google Account settings page. In this case opt_out_or_no_session will be returned.

You'll not be able to force users to use One Tap if they've opt out globally or if the exponential cooldown is active.

During development, on your account, you can follow the suggestions in the Answers to reset the cooldown.

bdid
  • 485
  • 2
  • 6