-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
24 lines (18 loc) · 773 Bytes
/
middleware.ts
File metadata and controls
24 lines (18 loc) · 773 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 { auth } from "@/lib/auth"
import { type NextRequest, NextResponse } from "next/server"
const protectedRoutes = ["/dashboard", "/provider", "/admin"]
const authRoutes = ["/auth/signin"]
export async function middleware(request: NextRequest) {
const session = await auth()
const pathname = request.nextUrl.pathname
if (authRoutes.some((route) => pathname.startsWith(route)) && session) {
return NextResponse.redirect(new URL("/dashboard", request.url))
}
if (protectedRoutes.some((route) => pathname.startsWith(route)) && !session) {
return NextResponse.redirect(new URL("/auth/signin", request.url))
}
return NextResponse.next()
}
export const config = {
matcher: ["/((?!_next/static|_next/image|.*\\.png|.*\\.jpg|.*\\.svg|api).*)"],
}