imagine / middleware.ts
github-actions[bot]
GitHub deploy: 8ac466cec7cb18a3cdc40223ab11ee9b5f5f569b
e6ce630
raw
history blame contribute delete
650 Bytes
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).*)'],
};