I attempted to add the Google Identity services script to nuxt.config.ts, which should expose window.google.
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
/* snip /*
head: {
script: [
{ src: "https://accounts.google.com/gsi/client" },
],
},
});
However, when I try to use it inside of a component, google is undefined.
<script setup lang="ts">
/* snip */
onMounted(() => {
// google is not defined
google.accounts.id.initialize({
client_id: "id.apps.googleusercontent.com",
callback: signInNew,
});
google.accounts.id.renderButton(document.getElementById("signIn")!, {
type: "standard",
});
google.accounts.id.prompt();
});
</script>
Upon further inspection, I found that the script is not added to the head at all. How can I fix this?