I'm migrating from Google Sign-in platform to the newer Google Identity Services library.
App.svelte:
<svelte:head>
<script src="https://accounts.google.com/gsi/client" async defer></script>
</svelte:head>
<div id="g_id_onload"
data-client_id="x.apps.googleusercontent.com"
data-callback="handleCredentialResponse">
</div>
<div class="g_id_signin"
data-type="standard"
data-size="large"
data-theme="outline"
data-text="sign_in_with"
data-shape="rectangular"
data-logo_alignment="left">
</div>
<script>
function decodeJwtResponse(token) {
let base64Url = token.split('.')[1]
let base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
let jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload)
}
let responsePayload;
function handleCredentialResponse(response) {
// decodeJwtResponse() is a custom function defined by you
// to decode the credential response.
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);
}
</script>
Reloading the page and I saw this error in the console:
[GSI_LOGGER]: The value of 'callback' is not a function. Configuration ignored.
What is the problem?
<script src="https://accounts.google.com/gsi/client" async defer></script>
) out of the svelte tag? If I modify your code that way, I can run this successfully. – Digitalize