How to keep the user logged in using Google client side javascript API with updated Google API


This Content is from Stack Overflow. Question asked by Srikanta Panigrahy

I am trying to implement google sign-in. I did, however the user is logging out after refresh action.

I have recently migrated to google’s updated javascript client-side script API.

The code is live at Expense by Cutezero.
I have used the below code to enable sign in

if (gapiInited && gisInited) {
        tokenClient.callback = async (resp) => {
            if (resp.error !== undefined) {
                throw (resp);
            // await listLabels();
            await listFiles();

        if (gapi.client.getToken() === null) {
            // Prompt the user to select an Google Account and asked for consent to share their data
            // when establishing a new session.
            tokenClient.requestAccessToken({ prompt: 'consent' });
        } else {
            // Skip display of account chooser and consent dialog for an existing session.
            tokenClient.requestAccessToken({ prompt: '' });

Please request more info in case you need it. But you can refer to the live-site to get more details.


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?