stickfigure
stickfigure

Reputation: 13556

How to determine if a user is logged in with hello.js?

How can I determine if a user is logged in with hello.js?

With the Google Sign-In SDK, I can register a callback with gapi.auth2.init() that will be called when the SDK is set up and ready to answer questions like "are you logged in?"

hello.js doesn't appear to have any such hook. At page load, the auth.login event will fire when the user is found to be logged in, but auth.logout is not fired when the user is found to be not logged in.

Upvotes: 3

Views: 1071

Answers (2)

Bola
Bola

Reputation: 758

Probably already solved but still.

I'm currently using event 'auth.login' which is run every time user successfully logs in. So basically you can define this event once, when initializing 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 happens here is that when user is logged in cookie is set. You can do some other stuff here like invoke callback method. Note that my example here is based on React.

Upvotes: 0

Bwyss
Bwyss

Reputation: 1834

You can use this:

hello.getAuthResponse('facebook'); // null if not logged in with FB, 

Upvotes: 3

Related Questions