我正在尝试在个人项目中设置“使用Google登录”,当我调用google auth路由时,在回调中收到“无法访问此网站的错误”。
app.get(
"/user/auth/google",
passport.authenticate("google", {
scope: [
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email"
]
})
);
app.get(
"/user/auth/google/callback",
passport.authenticate("google", {
successRedirect: "/wsup",
failureRedirect: "/login"
}),
(req, res) => {
console.log("callback called");
}
);
passport.use(
new googleStrategy(
{
clientID: process.env.googleClientID,
clientSecret: process.env.googleClientSecret,
callbackURL: "https://localhost:3000/user/auth/google/callback",
proxy: true
},
(accessToken, refreshToken, profile, done) => {
console.log(profile.emails[0].value);
User.findOne({ googleId: profile.id }).then(user => {
if (user) {
console.log("existing");
done(null, user);
} else {
new User({ googleId: profile.id })
.save()
.then(newUser => done(null, newUser));
}
});
}
)
);
回复文字:
This site can’t be reached. localhost unexpectedly closed the connection.
我想补充一点,我正在localhost上对其进行测试,并且可以在回调URl中看到来自Google的代码