I need a little help on how to create a sign out function from a website where you have sign in using your Google+ account.
The documentation states you should use the gapi.auth.signOut function
https://developers.google.com/+/web/signin/sign-out
But being a newbie to javascript I don't seem to have any luck.
This is my code - the sign out function is the part at the bottom. What am I doing wrong?
<script>
function signinCallback(authResult) {
if (authResult['status']['signed_in']) {
// Update the app to reflect a signed in user
// Hide the sign-in button now that the user is authorized, for example:
document.getElementById('signinButton').setAttribute('style','display: none ');
document.getElementById('callback').setAttribute('style','height: 100px;background-color: red ');
var mydiv = document.getElementById("callback");
var aTag = document.createElement('a');
aTag.innerHTML = "Sign out";
aTag.id= "signout";
mydiv.appendChild(aTag);
/*function checkid(){
document.getElementById('signout')
}*/
} else {
// Update the app to reflect a signed out user
// Possible error values:
// "user_signed_out" - User is signed-out
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatically log in the user
console.log('Sign-in state: ' + authResult['error']);
}
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById("signout").addEventListener('click', function(){
gapi.auth.signOut();
});
</script>