Handle credential responses with JavaScript functions

Handle credential response

You can set a JavaScript function in the data-callback attribute to handle the returned credential response. See the following code snippet:

<div id="g_id_onload"
  function handleCredentialResponse(response) {
     // decodeJwtResponse() is a custom function defined by you
     // to decode the credential response.
     const responsePayload = decodeJwtResponse(response.credential);

     console.log("ID: " + responsePayload.sub);
     console.log('Full Name: ' + responsePayload.name);
     console.log('Given Name: ' + responsePayload.given_name);
     console.log('Family Name: ' + responsePayload.family_name);
     console.log("Image URL: " + responsePayload.picture);
     console.log("Email: " + responsePayload.email);

You can validate and decode the JWT credential by using a JWT-decoding library for your language