Next-auth中间件'评估'不允许
我正在尝试实现一个简单的下一个授权中间件,以保护除/api/healthcheck
路由以外的所有API路由。
我在/pages/api/_middleware
中写下了以下内容,
import { withAuth } from 'next-auth/middleware';
// protect all api routes but /api/healthcheck
export default withAuth({
callbacks: {
authorized: async ({ req, token }) => {
if (req.page.name === '/api/healthcheck') return true;
if (token) return true;
return false;
},
},
});
这似乎在Localhost上正常工作,但是当我尝试构建以下错误时,我会得到以下错误,
Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Middleware pages/api/_middleware
任何想法会导致这一点?
I'm trying to implement a simple next-auth middleware to protect all api routes except a /api/healthcheck
route.
I wrote the following within /pages/api/_middleware
import { withAuth } from 'next-auth/middleware';
// protect all api routes but /api/healthcheck
export default withAuth({
callbacks: {
authorized: async ({ req, token }) => {
if (req.page.name === '/api/healthcheck') return true;
if (token) return true;
return false;
},
},
});
This seems to work correctly on localhost but when I try to build I get the following error
Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Middleware pages/api/_middleware
Any ideas what can cause this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
弄清楚了。
我误认为是授权回调
async
显然是被禁止的Figured it out.
I mistaken made the authorized callback
async
which apparently is forbidden