syncova-policies/middleware.ts
Weapie 328f042307 Syncova Policies: Portal für DSGVO-Datenschutzerklärungen
Next.js 15 App Router mit öffentlicher Übersicht und geschütztem
Admin-Bereich zur Pflege von Datenschutzerklärungen nach Art. 12ff. DSGVO.

- Oberfläche auf Basis von shadcn/ui, Inter lokal eingebunden
- Prisma/SQLite, Auth.js mit Credentials-Provider und Rollen
- Massenimport der Merkblätter des Amtes Leezen aus PDF
- Docker-Image (standalone) und Gitea-Workflow zur Veröffentlichung

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 16:23:51 +02:00

41 lines
1.2 KiB
TypeScript

import { auth } from "@/lib/auth"
export default auth((req) => {
// Allow access to public pages
if (req.nextUrl.pathname === "/" ||
req.nextUrl.pathname.startsWith("/auth/") ||
req.nextUrl.pathname.startsWith("/api/auth/") ||
req.nextUrl.pathname.startsWith("/api/privacy-policies")) {
return
}
// Check if user is authenticated for admin routes
if (req.nextUrl.pathname.startsWith("/admin") ||
req.nextUrl.pathname.startsWith("/api/users")) {
if (!req.auth) {
const url = new URL("/auth/signin", req.nextUrl.origin)
return Response.redirect(url)
}
// Check if user has admin access
const userRole = req.auth.user?.role
if (userRole !== "ADMIN" && userRole !== "SUPER_ADMIN") {
const url = new URL("/auth/signin", req.nextUrl.origin)
return Response.redirect(url)
}
}
})
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* Also match all API routes
*/
"/((?!_next/static|_next/image|favicon.ico).*)",
],
}