【发布时间】:2021-05-22 10:26:29
【问题描述】:
我正在尝试使用带有 passport.js 的 google + API 为我的网站启用注册和登录访问。
router.get("/api/v1.0/authentication/register/google",restrict({ unregistered: true }) ,passport.authenticate("google", {scope:["profile", "email"]}));
try{
router.get("/api/v1.0/google/callback", restrict({ unregistered: true }), passport.authenticate("google", {failureRedirect: "/"}), (req,res)=>{
console.log("success");
res.end("signed in");
// res.end("success")
});}
catch(error){
console.error(error);
}
这是我的 passport.js 文件,我在其中输入了我的 clientID 和密码。
passport.use(new GoogleStrategy({
clientID: "CLIENT_ID",
clientSecret: "CLIENT_SECRET",
callbackURL: "http://localhost:3000/api/v1.0/google/callback",
passReqToCallback : true
},
function(req, accessToken, refreshToken, profile, done) {
//register user here
if(req.body===null){
console.log("yes");
return done(null, false);
}
else{
console.log("the profile is:",profile);
}
}
));
每次我使用谷歌OAuth登录,但认证完成后不执行回调函数。它显示发生了错误。
【问题讨论】:
-
错误是什么?您可以将其添加到问题中吗?
-
它是网站失败时产生的错误信息。我正在使用一个名为 reeve (github.com/peterjoseph/Reeve) 的开源软件,因此它会自动生成一个错误,当请求或功能未完成或执行时会显示该错误。它只是说 {"status":500,"message":"看起来我们的系统出了点问题。不要惊慌!在我们的工程师调查期间,请随时与我们联系并提供以下代码以获取更多详细信息。代码:1he57cfbkklcavtpb"},我无法调试它导致错误也没有出现在控制台上
标签: javascript node.js express google-api passport.js