I did google connect to let users login using their google account.
What i did was, to create a button
<div class="g-signin2 social_signin" data-onsuccess="onSignIn"></div>
Then created onSignIn()
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log("Name: " + profile.getName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
};
</script>
Then send that token to PHP server for validation and fetching data. That works fine.
But my problem is that, when a user is logged out from my website, google automatically triggers 'onSignIn' without clicking on the button i created. So when user is logged out, user automatically get logged in again.
Can you help me here to prevent this automatic login? Or can i de-authorize the user?
Just add onclick and create global variable clicked (default false) and the variable is true you can call BasicProfile.
<div class="g-signin2 social_signin" onclick="ClickLogin()" data-onsuccess="onSignIn"></div>
<script>
var clicked=false;//Global Variable
function ClickLogin()
{
clicked=true;
}
function onSignIn(googleUser) {
if (clicked) {
profile = googleUser.getBasicProfile();
}
};
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With