Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React: Google "One Tap" callback function not being called

<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"}
like image 608
Bill Avatar asked Oct 26 '22 23:10

Bill


1 Answers

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.

like image 81
Guibin Avatar answered Nov 09 '22 16:11

Guibin