mirror of
https://gitlab.com/foxixus/neomovies.git
synced 2025-10-27 17:38:50 +05:00
23 lines
796 B
TypeScript
23 lines
796 B
TypeScript
|
|
import { getToken } from 'next-auth/jwt';
|
||
|
|
import { NextResponse } from 'next/server';
|
||
|
|
import type { NextRequest } from 'next/server';
|
||
|
|
|
||
|
|
export async function middleware(request: NextRequest) {
|
||
|
|
const token = await getToken({ req: request });
|
||
|
|
const isAuthPage =
|
||
|
|
request.nextUrl.pathname.startsWith('/login') ||
|
||
|
|
request.nextUrl.pathname.startsWith('/verify');
|
||
|
|
|
||
|
|
// Если пользователь авторизован и пытается зайти на страницу авторизации
|
||
|
|
if (token && isAuthPage) {
|
||
|
|
return NextResponse.redirect(new URL('/', request.url));
|
||
|
|
}
|
||
|
|
|
||
|
|
return NextResponse.next();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Указываем, для каких путей должен срабатывать middleware
|
||
|
|
export const config = {
|
||
|
|
matcher: ['/login', '/verify']
|
||
|
|
};
|