diff --git a/frontend/src/pages/_middleware.ts b/frontend/src/pages/_middleware.ts new file mode 100644 index 000000000..02cf77990 --- /dev/null +++ b/frontend/src/pages/_middleware.ts @@ -0,0 +1,11 @@ +import { NextResponse, NextRequest } from 'next/server'; +import { useHasAdminPermission } from '../components/Common/FirestoreDataProvider'; + +export default async function middleware(req: NextRequest) { + const hasAdminPersissions = useHasAdminPermission(); + const { pathname } = req.nextUrl; + if (pathname.startsWith('/admin') && !hasAdminPersissions) { + return NextResponse.redirect('/'); + } + return NextResponse.next(); +}