fist of all sorry for my bad english. I'm learning JavaScript, and i have a little problem with the Google O2Auth, in my node server i try to stop the code when the google token is invalid or expired, but the "return" inside the catch send the http response and i can see it in Postman but the code continue the execution and i have to put a awfull if to stop the code outside the catch.
Here is the Code
// The google code for NodeJS
async function verify(token) {
var ticket = await client.verifyIdToken({
idToken: token,
audience: GOOGLE_CLIENT_ID
});
var payload = ticket.getPayload();
return {
nombre: payload.name,
email: payload.email,
img: payload.picture,
google: true
}
}
// My code
app.post('/google', async (req, res) => {
var token = req.body.token;
// Here is the problem, in the .catch i put a return 403... but the code don't stop and enter in the Usuario.FindOne.
var googleUser = await verify(token).catch(err => {
return res.status(403).json({
ok: false,
mensaje: 'Token de google inválido',
errors: { message: 'Token de google inválido' }
});
});
Usuario.findOne({ email: googleUser.email }, (err, usuario) => {
if (err) {
return res.status(500).json({
ok: false,
...
...
...
Well the problem is that the code don't stop in the return "status 403", well after that function enter in the findOne function and brake the code if find any error...
No problem when the token is invalid because don't receive a email, but when the token is expired I receive a email, and my node server crashes!
The question is, I need to break the code in the verify(token).catch() how i can to this?
Thanks!