Next.js
The nextjs-auth repo demonstrates Casdoor integration in Next.js. Steps below.
Крок 1: Розгортання Casdoor
Deploy Casdoor in production mode. Confirm the login page works (e.g. at http://localhost:8000 with admin / 123 in dev).
Step 2: Add middleware
Put middleware.ts (or .js) at the project root (same level as pages or app, or inside src). Middleware runs before the request completes and can redirect or modify the response.
Example:
const protectedRoutes = ["/profile"];
export default function middleware(req) {
if (protectedRoutes.includes(req.nextUrl.pathname)) {
return NextResponse.redirect(new URL("/login", req.url));
}
}
See Next.js middleware.