/
IvanRyabchenko
/
random-coffee-admin
Обзор
Документация
Войти
/
IvanRyabchenko
/
random-coffee-admin
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/middleware.ts
25 строк
681 B
Ivan Ryabchenko
chore(init): initialize Next.js 14 project with TypeScript, Tailwind, Shadcn and Zustand
16 май 2026, 19:17
16 май 2026, 19:17
63b9715
Код
Авторство
О чём код?
import { NextRequest, NextResponse } from 'next/server' const PUBLIC_PATHS = ['/login'] const AUTH_COOKIE = 'auth_token' export function middleware(request: NextRequest): NextResponse { const { pathname } = request.nextUrl const token = request.cookies.get(AUTH_COOKIE)?.value const isPublicPath = PUBLIC_PATHS.includes(pathname) if (!token && !isPublicPath) { return NextResponse.redirect(new URL('/login', request.url)) } if (token && pathname === '/login') { return NextResponse.redirect(new URL('/dashboard', request.url)) } return NextResponse.next() } export const config = { matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'], }