s''
This commit is contained in:
16
app/page.tsx
16
app/page.tsx
@@ -170,9 +170,9 @@ export default function Home() {
|
||||
}, []);
|
||||
|
||||
const getOrCreateUserId = useCallback(async () => {
|
||||
// 优先使用 PocketBase 用户 ID(已登录时)
|
||||
// 优先使用 PocketBase 用户 ID(已登录时,含跨站 Cookie)
|
||||
try {
|
||||
const meRes = await fetch("/api/auth/me");
|
||||
const meRes = await fetch("/api/auth/me", { credentials: "include", cache: "no-store" });
|
||||
const meData = await meRes.json();
|
||||
if (meData?.user?.id) {
|
||||
const pbUserId = meData.user.id;
|
||||
@@ -239,9 +239,10 @@ export default function Home() {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: result.token, record: result.record }),
|
||||
credentials: "include",
|
||||
});
|
||||
const userId = result.record.id;
|
||||
const vipRes = await fetch("/api/vip/check");
|
||||
const vipRes = await fetch("/api/vip/check", { credentials: "include", cache: "no-store" });
|
||||
const vipData = await vipRes.json();
|
||||
if (vipData?.vip) {
|
||||
setStorage("userId", userId);
|
||||
@@ -307,7 +308,7 @@ export default function Home() {
|
||||
|
||||
const handlePay = useCallback(async () => {
|
||||
try {
|
||||
const meRes = await fetch("/api/auth/me");
|
||||
const meRes = await fetch("/api/auth/me", { credentials: "include", cache: "no-store" });
|
||||
const meData = await meRes.json();
|
||||
if (meData?.user?.id) {
|
||||
doPay();
|
||||
@@ -368,16 +369,17 @@ export default function Home() {
|
||||
return;
|
||||
}
|
||||
|
||||
// SSO: 优先检查根域 Cookie(跨站登录态)
|
||||
// SSO: 优先检查根域 Cookie(跨站登录态,如从 digital 登录后跳转过来)
|
||||
try {
|
||||
const meRes = await fetch("/api/auth/me");
|
||||
const meRes = await fetch("/api/auth/me", { credentials: "include", cache: "no-store" });
|
||||
const meData = await meRes.json();
|
||||
if (meData?.user && meData?.token) {
|
||||
const { pbSaveAuth } = await import("@/app/lib/pocketbase");
|
||||
pbSaveAuth(meData.token, { id: meData.user.id, email: meData.user.email });
|
||||
const vipRes = await fetch("/api/vip/check");
|
||||
const vipRes = await fetch("/api/vip/check", { credentials: "include", cache: "no-store" });
|
||||
const vipData = await vipRes.json();
|
||||
if (vipData?.vip) {
|
||||
setStorage("userId", meData.user.id);
|
||||
savePaidType("vip");
|
||||
saveUserName(meData.user.email || meData.user.id);
|
||||
setLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user