-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmiddleware.ts
More file actions
25 lines (19 loc) · 803 Bytes
/
middleware.ts
File metadata and controls
25 lines (19 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
export function middleware(request: NextRequest) {
// Skip middleware for server actions to avoid breaking them
if (request.headers.get('next-action')) {
return NextResponse.next()
}
// Example: Check if the user is authenticated for protected routes
const isAuthenticated = true // Replace with actual auth check
// If the request is for the settings page and the user is not authenticated
if (request.nextUrl.pathname.startsWith("/settings") && !isAuthenticated) {
// Redirect to the login page
return NextResponse.redirect(new URL("/login", request.url))
}
return NextResponse.next()
}
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
}