Initial commit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
谢宇宁
2026-10-26 17:51:31 +07:00
co-authored by Claude Opus 5.5
commit 61d0a11dfa
371 changed files with 35836 additions and 0 deletions
@@ -0,0 +1,52 @@
"use client";
import { useEffect, useState } from "react";
import { ensureGuestSession } from "@/lib/auth/session";
import { tracker } from "@/lib/tracker";
/**
* 仅在挂载后异步拉游客会话,不参与 SSR / 首屏阻塞。
* ensureGuestSession 本地有缓存时会同步返回并后台 refresh。
*/
export function GuestAuthBootstrap() {
const [error, setError] = useState<string | null>(null);
useEffect(() => {
let cancelled = false;
// 不 await:失败/超时也不拖住其它渲染
void ensureGuestSession()
.then((user) => {
if (cancelled || !user) return;
// 埋点 uid:SDK 要求非空时长度 ≥ 4
tracker.setUid(String(user.userId || ""));
if (process.env.NODE_ENV === "development") {
console.info("[guest-auth]", {
userId: user.userId,
nickName: user.nickName,
isRegister: user.isRegister,
loginType: user.loginType,
});
}
})
.catch((err: unknown) => {
if (cancelled) return;
const message = err instanceof Error ? err.message : "游客登录失败";
setError(message);
console.error("[guest-auth]", err);
});
return () => {
cancelled = true;
};
}, []);
if (process.env.NODE_ENV !== "development" || !error) return null;
return (
<div className="pointer-events-none fixed right-3 bottom-3 z-[60] max-w-xs rounded-lg bg-black/80 px-3 py-2 text-xs text-[#FF8FA8]">
游客登录失败:{error}
</div>
);
}