Abd*_*eer 5 javascript reactjs next.js next-auth
我已经按照文档中的方式实现了 next-auth,当我访问 http://localhost:3001/api/auth/signin 时,我看到了这个

之后,当我单击“使用 google 或 github 登录”时,我的页面会刷新并被重定向到http://localhost:3001/api/auth/signin?csrf=true之后没有任何反应。它是同一页面。
我的 [...nextauth.js] 文件
import NextAuth from "next-auth";
import Providers from "next-auth/providers";
export default NextAuth({
providers: [
Providers.Google({
clientId: process.env.GOOGLE_CLIENT,
clientSecret: process.env.GOOGLE_KEY,
}),
Providers.GitHub({
clientId: process.env.GITHUB_CLIENT,
clientSecret: process.env.GITHUB_SECRET,
}),
],
});
Run Code Online (Sandbox Code Playgroud)
任何想法,为什么它不起作用
我认为它与我的节点表达服务器有关,其代码是
const express = require("express");
const app = express();
const server = require("http").createServer(app);
const next = require("next");
const nextApp = next({ dev: true });
const nextHandler = nextApp.getRequestHandler();
/*******************ROUTES****************/
const userRoutes = require("./server/routes/user");
nextApp.prepare().then(() => {
app.use("/node/user", userRoutes);
app.all("*", (req, res) => nextHandler(req, res));
server.listen(3001, err => {
if (err) throw err;
console.log("> ---------Server is ready on port 3001------------");
});
});
Run Code Online (Sandbox Code Playgroud)
我有类似的东西,也使用自定义快递服务器。看看你最终会在何时为 falsenext-auth/dist/server/index.js时点击该重定向。csrfTokenVerified就我而言,csrf 令牌是随signin/[provider]请求一起发送的。我认为客户端正在发送 urlencoded 的请求主体,并且这没有被 Express 服务器解析,因此从未将其发送到下一个身份验证服务器端点。我使用节点包修复了它bodyparser,并将这一行添加到我的快速服务器设置中app.use(urlencoded({ extended: true }));。我在下一个 v9 中没有遇到这个问题,但在较新的版本中却遇到了这个问题。
| 归档时间: |
|
| 查看次数: |
2341 次 |
| 最近记录: |