I'm building a "Login with Google" button in my app using the Google API and the official guide, but i got stuck at decrypting the credentials sent by google as a response when login in with google. I get this error: Uncaught SyntaxError: Cannot use import statement outside a module
This is the form file:
<script src="https://accounts.google.com/gsi/client" async defer></script>
<div id="g_id_onload"
data-client_id="*********************************************"
data-callback="handleCredentialResponse"
data-auto_prompt="false"
>
</div>
<div class="g_id_signin"
data-type="standard"
data-size="large"
data-width="400"
data-theme="outline"
data-text="sign_in_with"
data-shape="rectangular"
data-logo_alignment="left">
</div>
And a js file login.js dealing with the response:
import * as jose from '../vendor/jose-main/src/index.ts';
function handleCredentialResponse(response) {
const { payload, protectedHeader } = await jose.jwtDecrypt(response.credential, secretKey, {
issuer: 'urn:example:issuer',
audience: 'urn:example:audience'
})
console.log(payload);
console.log(protectedHeader);
// 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);
}
Anyone knows how to solve this issue?