'App crashes instantly after opening google sign in screen
The app crashes whenever I go to Google Sign in screen. I don't even have to click anything, it just crashes.
Error: The verifyIdToken method requires an ID Token at OAuth2Client.verifyIdTokenAsync (/app/node_modules/google-auth-
Google Login Implementation:
exports.googleController = (req, res) => {
try {
const { idToken } = req.body;
client
.verifyIdToken({ idToken, audience: process.env.GOOGLE_CLIENT })
.then((response) => {
console.log("GOOGLE LOGIN RESPONSE", response);
const { email_verified, name, email } = response.payload;
if (email_verified) {
User.findOne({ email }).exec((err, user) => {
if (user) {
const token = jwt.sign({ _id: user._id }, process.env.JWT_SEC, {
expiresIn: "7d",
});
const { _id, email, name, isAdmin } = user;
return res.json({
token,
user: { _id, email, name, isAdmin },
});
} else {
let password = email + process.env.JWT_SEC;
user = new User({ name, email, password });
user.save((err, data) => {
if (err) {
console.log("ERROR GOOGLE LOGIN ON USER SAVE", err);
return res.status(400).json({
error: "User signup failed with google",
});
}
const token = jwt.sign({ _id: data._id }, process.env.JWT_SEC, {
expiresIn: "7d",
});
const { _id, email, name, isAdmin } = data;
return res.json({
token,
user: { _id, email, name, isAdmin },
});
});
}
});
} else {
return res.status(400).json({
error: "Google login failed. Try again",
});
}
});
} catch (err) {
console.log(err);
}
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
