Files
app-padel/apps/web/middleware.ts
2026-02-01 06:24:07 +00:00

28 lines
617 B
TypeScript

import { withAuth } from 'next-auth/middleware';
import { NextResponse } from 'next/server';
export default withAuth(
function middleware(req) {
const token = req.nextauth.token;
const pathname = req.nextUrl.pathname;
// Check for SUPER_ADMIN only routes
if (pathname.startsWith('/admin/settings')) {
if (token?.role !== 'SUPER_ADMIN') {
return NextResponse.redirect(new URL('/admin', req.url));
}
}
return NextResponse.next();
},
{
callbacks: {
authorized: ({ token }) => !!token,
},
}
);
export const config = {
matcher: ['/admin/:path*'],
};