5
<script src="https://accounts.google.com/gsi/client"></script>
...
declare var google: any;
...

  useEffect(() => {
    const handleCredentialResponse = (response: any) => {
      console.log(response);
    };
    const client_id = process.env.REACT_APP_GOOGLE_CLIENT_ID;
    const callback = handleCredentialResponse;
    const auto_select = true;
    google.accounts.id.initialize({ client_id, callback, auto_select });
    google.accounts.id.prompt((notification: any) => {
      console.log(notification);
    });
  }, []);

Why does handleCredentialResponse not get called at all? The user is prompted to log in, they hit continue and then the function never gets called! Grrr! Above taken from docs here and also here

The notification logs out

nl {g: "display", h: true}
nl {g: "skipped", l: "issuing_failed"}
Bill
  • 4,614
  • 13
  • 77
  • 132

3 Answers3

2

are you testing locally? As mentioned here, you need to add both http://localhost and http://localhost:port_number to the Authorized JavaScript origins box.

Guibin
  • 734
  • 3
  • 5
0

using the js to resolve this issue,

       window.google.accounts.id.initialize({
          client_id: ${clientId},
          callback: data => handleToken(data),
        })
    
It is not clear why the callback method does not take effect in html
liubility
  • 31
  • 1
0

I am not sure why, but try adding handleCredentialResponse to the window object. In other words add the following code below the function. I got this answer from this link [GSI_LOGGER]: The value of 'callback' is not a function. Configuration ignored

window.handleCredentialResponse = handleCredentialResponse
Dennis Mwebia
  • 21
  • 1
  • 4