Failed to retrieve verification certificates error

Trying to add google auth I faced an issue:

Here is the client code:

function onSignIn(googleUser) {
    var id_token = googleUser.getAuthResponse().id_token;
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/google-login');
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.onload = function() {
        // console.log('Signed in as: ' + xhr.responseText);
        if(xhr.responseText == 'success'){
            signOut();
            // location.assign('/profile')
        }
    };
    xhr.send(JSON.stringify({token : id_token}));
}

And here is the end point in server:

app.post('/google-login', (req,res) => {

    let token = req.body.token;

    console.log('token', token)

    async function verify() {
        const ticket = await client.verifyIdToken({
            idToken: token,
            audience: CLIENT_ID,  // Specify the CLIENT_ID of the app that accesses the backend
        });
        const payload = ticket.getPayload();
        const userid = payload['sub'];
        // console.log("payload*********************************", console.log(payload))
    }

    verify()
        .then((e)=> {
            // res.cookie('session-token', token);
            // console.log(e)
            res.send('success')
        })
        .catch(err => console.log(err));

})

I get the token in the above console log successfully but just after that I get this error:

GaxiosError: Failed to retrieve verification certificates:

enter image description here

Note: I'm using the this code.

Note 2: I'm testing this on http://localhost:4000



Read more here: https://stackoverflow.com/questions/68476115/failed-to-retrieve-verification-certificates-error

Content Attribution

This content was originally published by Sara Ree at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: