refactor(splash): convert Skip to explicit guest login flow
- Splash Skip button now dispatches `AuthGuestLoginSubmitted` instead of
direct routing, keeping guest auth under the state machine
- Update PWA install dialog copy ("Add to Home Screen") and drop favicon
entry from manifest icons
- Add debug logging and routing sequence docs to splash-button
This commit is contained in:
+27
-2
@@ -23,11 +23,16 @@
|
||||
* - 函数导出名建议为 `proxy`(可默认导出)。
|
||||
*
|
||||
* 用 `src/` 时 proxy 必须放在 `src/` 内(参见 `src-folder.md`)。
|
||||
*
|
||||
* DEBUG:每条请求都打日志(`hasSession` / `isAuthOnly` / `isProtected` + 决策),
|
||||
* 用于排查"进入 /splash 后仍自动跳 /chat"类路由 bug。bug 修完可考虑保留 INFO 级别 + 删 DEBUG。
|
||||
*/
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
import { Logger } from "@/utils/logger";
|
||||
|
||||
import {
|
||||
AUTH_ONLY_ROUTES,
|
||||
PROTECTED_ROUTES,
|
||||
@@ -40,6 +45,9 @@ const SESSION_COOKIE_NAMES = [
|
||||
"__Secure-next-auth.session-token",
|
||||
];
|
||||
|
||||
/** proxy 入口日志(Node.js runtime 跑,pino 兼容) */
|
||||
const log = new Logger("Proxy");
|
||||
|
||||
function isAuthOnlyRoute(pathname: string): boolean {
|
||||
return (AUTH_ONLY_ROUTES as readonly string[]).includes(pathname);
|
||||
}
|
||||
@@ -58,21 +66,38 @@ export function proxy(request: NextRequest) {
|
||||
const hasSession = SESSION_COOKIE_NAMES.some(
|
||||
(name) => Boolean(request.cookies.get(name)?.value),
|
||||
);
|
||||
const isAuthOnly = isAuthOnlyRoute(pathname);
|
||||
const isProtected = isProtectedRoute(pathname);
|
||||
|
||||
// DEBUG:每条请求都打(区分 path 1=proxy 跳 vs path 2=splash useEffect 跳)
|
||||
log.info(
|
||||
{ pathname, hasSession, isAuthOnly, isProtected },
|
||||
"[proxy] request",
|
||||
);
|
||||
|
||||
// 已登录访问未登录专属页 → /chat
|
||||
if (hasSession && isAuthOnlyRoute(pathname)) {
|
||||
if (hasSession && isAuthOnly) {
|
||||
log.info(
|
||||
{ pathname, target: ROUTES.chat, reason: "logged-in → auth-only" },
|
||||
"[proxy] redirect",
|
||||
);
|
||||
const url = request.nextUrl.clone();
|
||||
url.pathname = ROUTES.chat;
|
||||
return NextResponse.redirect(url, 308);
|
||||
}
|
||||
|
||||
// 未登录访问登录态专属页 → /splash(首界面)
|
||||
if (!hasSession && isProtectedRoute(pathname)) {
|
||||
if (!hasSession && isProtected) {
|
||||
log.info(
|
||||
{ pathname, target: ROUTES.splash, reason: "not-logged-in → protected" },
|
||||
"[proxy] redirect",
|
||||
);
|
||||
const url = request.nextUrl.clone();
|
||||
url.pathname = ROUTES.splash;
|
||||
return NextResponse.redirect(url, 308);
|
||||
}
|
||||
|
||||
log.info({ pathname }, "[proxy] pass-through");
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user