【发布时间】:2018-06-22 05:14:54
【问题描述】:
我尝试登录到使用 Google OAuth 流程的应用程序。我过去已经成功登录到此应用程序,前往
localhost:5000/auth/google
当我选择我的电子邮件时,该过程会挂起大约一分钟,然后我得到:
TokenError: Code was already redeemed.
这发生在localhost:5000/auth/google/callback,我认为这可能不是问题,因为它是我下面的authRoutes.js 文件中的一条路线:
const passport = require('passport');
module.exports = (app) => {
app.get(
'/auth/google',
passport.authenticate('google', {
scope: ['profile', 'email']
})
);
app.get('/auth/google/callback', passport.authenticate('google'));
app.get('/api/logout', (req, res) => {
req.logout();
// prove to whoever is
// making request that
// they are no longer signed in
res.send(req.user);
});
app.get('/api/current_user', (req, res) => {
res.send(req.user);
});
};
我想我会通过转到 localhost:5000/api/current_user 进行检查,这应该将用户的 googleID 和 _id 呈现为一个对象,但是我得到一个空白屏幕,这意味着我没有成功登录。
我不确定这里发生了什么。
【问题讨论】:
-
我问你这个,你用的是数据库吗?如果是,您的数据库是否正在运行?
-
@Daniel,是的,我刚刚意识到我忘了打开我的 MongoDB 数据库。谢谢你,请发表你的答案。
标签: node.js passport-google-oauth