Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import { NextRequest, NextResponse } from "next/server"; interface CustomRequestCookies { "couchers-sesh"?: string; } export function middleware( req: NextRequest & { cookies: CustomRequestCookies } ) { // Redirect to dashboard if user is logged in and visits the root path Iif (req.cookies.get("couchers-sesh")?.value && req.nextUrl.pathname === "/") { const url = req.nextUrl.clone(); url.pathname = "/dashboard"; return NextResponse.rewrite(url); } return NextResponse.next(); } // Add matcher to apply the middleware to the root path export const config = { matcher: ["/", "/dashboard"], // Only apply to these paths }; |