4132b80ee0
- 新增对话列表、聊天、角色详情、书架详情及个人资料独立路由 - 导航使用真实链接,补齐历史返回、登录深链与会话草稿恢复 - 搜索筛选由 URL 驱动,修复浏览器返回时丢失筛选的问题 - 补齐路由校验回归、页面加载与异常入口,并同步 README
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
/** 私有页面会话路由,默认登录后进入数字人空间。 */
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
import { digitalLoginPath, safeDigitalReturnTo } from "@/lib/digital-routes";
|
|
|
|
const protectedRoutes = [
|
|
"/discover",
|
|
"/chats",
|
|
"/characters",
|
|
"/library",
|
|
"/profile",
|
|
"/dashboard",
|
|
"/tasks",
|
|
"/schedule",
|
|
"/announcements",
|
|
"/store",
|
|
"/me",
|
|
];
|
|
const publicRoutes = ["/", "/login"];
|
|
const cookieName = process.env.ROLE_USER_SESSION_COOKIE || "role_user_session";
|
|
|
|
/** 路由级登录保护;深链携带站内回跳目标,不丢失具体聊天地址。 */
|
|
export function proxy(request: NextRequest) {
|
|
const path = request.nextUrl.pathname;
|
|
const hasSession = Boolean(request.cookies.get(cookieName)?.value);
|
|
const isProtected = protectedRoutes.some(
|
|
(route) => path === route || path.startsWith(`${route}/`),
|
|
);
|
|
const isPublic = publicRoutes.includes(path);
|
|
|
|
if (isProtected && !hasSession) {
|
|
return NextResponse.redirect(
|
|
new URL(digitalLoginPath(path + request.nextUrl.search), request.url),
|
|
);
|
|
}
|
|
|
|
if (isPublic && hasSession) {
|
|
return NextResponse.redirect(
|
|
new URL(
|
|
path === "/login"
|
|
? safeDigitalReturnTo(request.nextUrl.searchParams.get("next"))
|
|
: "/discover",
|
|
request.url,
|
|
),
|
|
);
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
/** 只拦截业务页面,不影响 BFF、静态资源和安装文件。 */
|
|
export const config = {
|
|
matcher: [
|
|
"/((?!api|_next/static|_next/image|manifest.webmanifest|sw.js|.*\\..*).*)",
|
|
],
|
|
};
|