I'm currently utilizing
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b0ded5c8c49dd1c5c4d8f0849e81889e87">[email protected]</a>
& <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="056b607d714534362b">[email protected]</a>
, and I am facing an issue with my middleware.ts file. Despite several changes I've made, it has stopped working abruptly. All attempts to call it have been unsuccessful.
middleware.ts
import { withAuth } from "next-auth/middleware";
export default withAuth({
callbacks: {
authorized({ req, token }) {
const { pathname } = req.nextUrl;
console.log(token, pathname); // this log never comes
if (pathname.startsWith("/admin")) {
return token?.roleLabel === "ADMIN" || token?.userRole === "admin";
}
// `/me` only requires the user to be logged in
return !!token;
},
},
});
export const config = {
matcher: ["/admin/:path*", "/c/:path*", "/me"],
};
next.config.js
const { i18n } = require("./next-i18next.config");
const { PHASE_DEVELOPMENT_SERVER } = require("next/constants");
module.exports = (phase) => {
let extensions = ['page.tsx', 'page.ts', 'page.jsx', 'page.js', 'api.ts', 'api.js']
if (phase === PHASE_DEVELOPMENT_SERVER) extensions.push('doc.tsx')
return {
i18n,
pageExtensions: extensions,
images: {
domains: ['domain.com'],
},
}
};
Should I consider renaming my middleware.ts file to middleware.page.ts? I attempted this, but it did not resolve the issue. The file is currently located in my root folder, and moving it to pages/ directory did not yield any positive results.
Authentication is functioning correctly on the React side, but I am unable to intercept all protected pages with the middleware. Assistance would be greatly appreciated.