import { NextResponse } from 'next/server'; import type { NextRequest } from 'next/server'; export function middleware(request: NextRequest) { const { pathname } = request.nextUrl; // Protect dashboard routes if (pathname.startsWith('/dashboard')) { const authToken = request.cookies.get('Authorization')?.value; if (!authToken) { // Redirect to login if no token is found const loginUrl = new URL('/auth/login', request.url); loginUrl.searchParams.set('redirectUrl', pathname); return NextResponse.redirect(loginUrl); } } return NextResponse.next(); } // See "Matching Paths" below to learn more export const config = { matcher: ['/dashboard/:path*'], };