(req: NextRequest)
| 15 | } |
| 16 | |
| 17 | export default async function authMiddleware(req: NextRequest) { |
| 18 | const session = await getMiddlewareSession(req); |
| 19 | const pathname = req.nextUrl.pathname |
| 20 | const url = req.url |
| 21 | |
| 22 | if(pathname === "/"){ |
| 23 | return NextResponse.redirect(new URL("/dashboard", url)) |
| 24 | } |
| 25 | |
| 26 | if(pathname.startsWith("/dashboard")){ |
| 27 | if(session){ |
| 28 | return NextResponse.next() |
| 29 | } |
| 30 | |
| 31 | return NextResponse.redirect(new URL("/sign-in", url)) |
| 32 | } |
| 33 | |
| 34 | if(pathname.startsWith("/sign-")){ |
| 35 | if(!session){ |
| 36 | return NextResponse.next() |
| 37 | } |
| 38 | |
| 39 | return NextResponse.redirect(new URL("/dashboard", url)) |
| 40 | } |
| 41 | |
| 42 | return NextResponse.next(); |
| 43 | } |
| 44 | |
| 45 | export const config = { |
| 46 | matcher: [ |
nothing calls this directly
no test coverage detected