How to determine if a user is logged in using hello.js?
How can I determine if a user is logged in with hello.js?
With the Google Login SDK, I can register a callback with a help gapi.auth2.init()
that will be called when the SDK is set up and ready to answer questions like "are you signed in?"
hello.js doesn't seem to have such a hook. On page load, the event is auth.login
fired when the user is detected to log in, but auth.logout
not triggered when the user cannot log in.
source to share
It may have already been decided, but still.
I am currently using the auth.login event, which fires every time a user logs in successfully. So you can define this event once when you initialize hello js.
hello.on('auth.login', function (response) {
console.log('on auth login');
console.log(response);
const cookies = new Cookies();
let auth = response.authResponse;
cookies.set('auth', auth.access_token, {path: '/', maxAge: auth.expires_in});
callback(param);
});
What's going on here is that when the user enters the cookie. You can do some other things here like calling the callback method. Note that my example here is based on React.
source to share