Fix – Gapi is not defined – Google sign in issue with gapi.auth2.init
Posted on: February 11, 2021 by Deven
If you are facing this issue, Gapi is not defined – Google sign-in issue with gapi.auth2.Init, The most common problem is you have async and defer attributes on your script tag. Please note that gapi should be loaded after your script tag with gapi.auth2.init
.
Consider the example below:
<script src="https://apis.google.com/js/platform.js?onload=onLoadCallback" async defer></script>
<script>
window.onLoadCallback = function(){
gapi.auth2.init({
client_id: 'You_client_Id_HERE.apps.googleusercontent.com'
});
}
</script>
In the snippet above to wait for gapi
before executing the code you have to use onload query param in the script tag.
Share on social media
//