'Next-auth middleware 'eval' not allowed
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?
Solution 1:[1]
Figured it out.
I mistaken made the authorized callback async
which apparently is forbidden
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Michael Pomogajko |