/
lex87
/
p08-echo-platform
Обзор
Документация
Войти
/
lex87
/
p08-echo-platform
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
apps/web/src/proxy.ts
31 строка
1 KB
Axentra
feat(auth): T-013 route protection + real child name in header + login redirect
30 июн 2026, 01:12
30 июн 2026, 01:12
458686a
Код
Авторство
О чём код?
import { NextRequest, NextResponse } from "next/server"; import { verifyToken } from "@/lib/auth"; const PROTECTED = ["/diary", "/skills", "/insights", "/settings", "/onboarding"]; const AUTH_PAGES = ["/auth/login", "/auth/register"]; export async function proxy(req: NextRequest) { const { pathname } = req.nextUrl; const isProtected = PROTECTED.some((p) => pathname.startsWith(p)); const isAuthPage = AUTH_PAGES.some((p) => pathname.startsWith(p)); const token = req.cookies.get("echo_session")?.value; const session = token ? await verifyToken(token) : null; if (isProtected && !session) { const url = new URL("/auth/login", req.url); url.searchParams.set("from", pathname); return NextResponse.redirect(url); } if (isAuthPage && session) { return NextResponse.redirect(new URL("/diary", req.url)); } return NextResponse.next(); } export const config = { matcher: ["/diary/:path*", "/skills/:path*", "/insights/:path*", "/settings/:path*", "/onboarding/:path*", "/auth/:path*"], };