Skip to content

Instantly share code, notes, and snippets.

@josephkandi
Last active May 9, 2018 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephkandi/002d37aa8d4ac09716306c13130f0f69 to your computer and use it in GitHub Desktop.
Save josephkandi/002d37aa8d4ac09716306c13130f0f69 to your computer and use it in GitHub Desktop.
var auth2;
var loggedInPara = document.getElementById('login-status');
gapi.load('auth2', function(){
auth2 = gapi.auth2.init({
client_id: 'app-id.apps.googleusercontent.com'
});
loggedInPara.textContent = (auth2.isSignedIn.get()) ? 'User is logged in' : 'User is logged out';
auth2.attachClickHandler('signin-button', {}, onSuccess, onFailure);
});
var onSuccess = function(user) {
console.log('Signed in as ' + user.getBasicProfile().getName());
};
var onFailure = function(error) {
console.log(error);
};
function signOut() {
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
function isLoggedIn(){
return auth2.isSignedIn.get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment