docs(naming): rename middleware.md to proxy.md (next 16)
docs/patterns/middleware.md → docs/patterns/proxy.md following the Next.js 16 proxy.ts rename. Update link in CLAUDE.md.
This commit is contained in:
parent
c4ce3d7885
commit
e9d6b8a255
2 changed files with 1 additions and 1 deletions
35
docs/patterns/proxy.md
Normal file
35
docs/patterns/proxy.md
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Patroon: Proxy (route protection)
|
||||
|
||||
In Next.js 16 hernoemd van `middleware.ts` naar `proxy.ts`, functienaam van `middleware` naar `proxy`.
|
||||
|
||||
```ts
|
||||
// proxy.ts
|
||||
import { NextResponse } from 'next/server'
|
||||
import type { NextRequest } from 'next/server'
|
||||
import { sessionOptions } from '@/lib/session'
|
||||
|
||||
const protectedRoutes = ['/dashboard', '/products', '/todos', '/settings']
|
||||
const authRoutes = ['/login', '/register']
|
||||
|
||||
export function proxy(request: NextRequest) {
|
||||
const path = request.nextUrl.pathname
|
||||
const isProtected = protectedRoutes.some(r => path.startsWith(r))
|
||||
const isAuthRoute = authRoutes.some(r => path.startsWith(r))
|
||||
|
||||
// Cookie-aanwezigheid controleren — volledige sessievalidatie in layout.tsx
|
||||
const hasSession = !!request.cookies.get(sessionOptions.cookieName)?.value
|
||||
|
||||
if (isProtected && !hasSession) {
|
||||
return NextResponse.redirect(new URL('/login', request.url))
|
||||
}
|
||||
if (isAuthRoute && hasSession) {
|
||||
return NextResponse.redirect(new URL('/dashboard', request.url))
|
||||
}
|
||||
|
||||
return NextResponse.next()
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue