0

My site is implementing Google Sign-In with the code below and it's working pretty well.

When I try to do it in the mobile version, it works, but I don't get the answer of sign in. I guess it's because mobile version doesn't show a popup but a new tab (Facebook has the same behavior as well...)

How should I proceed to get it to work in the mobile version too?

gapi.load('auth2', function() {});

$(function() {
  $("#btn-google-login").on('click', function() {

    var proccedLogin = function(resp) {
      // my continue code...
    }

    // Retrieve the singleton for the GoogleAuth library and set up the client.
    auth2 = gapi.auth2.init({
      client_id: $('meta[name="google-signin-client_id"]').attr('content'),
      cookiepolicy: 'single_host_origin',
      prompt: 'consent',
      immediate: false
    }, function() {});

    auth2.signIn()
      .then(proccedLogin)
      .catch(function(error) {
        alert(JSON.stringify(error, undefined, 2))
      })

  }) // btn google click
})

P.S. The error I get is 'popup_closed_by_user', but I didn't closed the tab by my own.

Edit

Now I'm getting 'popup_blocked_by_browser'. I followed some changes described in the link below but it just returns the same error...

detect error: "popup_blocked_by_browser" for google auth2 in javascript

nda
  • 541
  • 7
  • 18
Marco A. Braghim
  • 516
  • 1
  • 5
  • 19

1 Answers1

0

Try this : Promise.resolve(gapi.auth2.getAuthInstance().signIn()).then source:https://github.com/google/google-api-javascript-client/issues/232

I_Al-thamary
  • 3,385
  • 2
  • 24
  • 37
  • I don't know if was it the problem, on my own cell phone it doesn't working yet (it's a very old iPhone 4 rsrsrs), but I tested with others devices and ok... So let's say it is the solution, for now... – Marco A. Braghim Dec 27 '18 at 11:48
  • @MarcoA.Braghim try to read more in the link that I gave with the answer to understand more about the problem. But, I think it solves the problem. – I_Al-thamary Dec 27 '18 at 11:57
  • Point is that this behavior was already just like it is now, I mean, nothing have changed even with this code change, so... – Marco A. Braghim Dec 27 '18 at 15:32