Spaces:
Running
Running
File size: 650 Bytes
e6ce630 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
const isAuthenticated = request.cookies.get('isAuthenticated')?.value === 'true';
const isPasswordPage = request.nextUrl.pathname === '/password';
if (!isAuthenticated && !isPasswordPage) {
return NextResponse.redirect(new URL('/password', request.url));
}
if (isAuthenticated && isPasswordPage) {
return NextResponse.redirect(new URL('/', request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
|