无法获取/auth/google:PassportJS google Oauth策略



我正在尝试在我的应用程序中实现googleoauth2策略。当我到达路线时http://localhost:3000/auth/google我得到:无法获取/auth/google。似乎没有创建此路线。我正在使用护照文件,这是我的代码:

passport.use(
new GoogleStrategy(
{
clientID: googleClientId,
clientSecret: googleClientSecret,
callbackURL: "http://localhost:3000/auth/google/callback",
passReqToCallback: true,
},
function (request, accessToken, refreshToken, profile, done) {
return done(err, profile);
}
)
);

我的身份验证请求是:


app.get(
"/auth/google",
passport.authenticate("google", { scope: ["email", "profile"] })
);
app.get(
"/auth/google/callback",
passport.authenticate("google", {
successRedirect: "/dashboard",
failureRedirect: "/users/login",
})
);

我不知道我做错了什么。请帮我解决这个问题。感谢

const passport=require("passport&"(

app.use(passport.initialize(((在您的index.js或服务器中提供的索引文件名称中使用此项。

因为在我的app.js中我使用了

app.use("/users", require("./routes/users.js"));

所以,我必须到达的实际路线是localhost:3000/users/auth/google

最新更新