This commit is contained in:
eric
2026-03-31 14:08:38 -05:00
parent f25d9141b3
commit 186064c20d
2 changed files with 22 additions and 10 deletions

View File

@@ -522,10 +522,11 @@ export default function HomeClient() {
async (userId: string): Promise<boolean> => {
try {
const normalizedUserId = userId.trim();
const prioritizedUserId = resolveVipLookupUserId(normalizedUserId);
const res = await fetch("/api/vip/check-by-user", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ user_id: normalizedUserId }),
body: JSON.stringify({ user_id: prioritizedUserId }),
credentials: "same-origin",
cache: "no-store",
});
@@ -535,16 +536,20 @@ export default function HomeClient() {
return false;
}
if (probe === "no") {
if (prioritizedUserId && prioritizedUserId !== normalizedUserId) {
return false;
}
savePaidType(null);
return false;
}
if (!data?.vip) {
return false;
}
setStorage("userId", normalizedUserId);
if (/^user\d+$/.test(normalizedUserId)) {
setStorage("memosAccount", normalizedUserId);
setAnonymousUserCookie(normalizedUserId);
const resolvedUserId = prioritizedUserId || normalizedUserId;
setStorage("userId", resolvedUserId);
if (/^user\d+$/.test(resolvedUserId)) {
setStorage("memosAccount", resolvedUserId);
setAnonymousUserCookie(resolvedUserId);
}
savePaidType("vip");
if (data?.alreadyLinked && data?.email) {
@@ -557,12 +562,12 @@ export default function HomeClient() {
await recoverLinkedVipSession(
linkedEmail,
DEFAULT_EMAIL_PASSWORD,
normalizedUserId
resolvedUserId
).catch(() => {});
} else {
const linked = getStorage("emailLinked") === "1";
const hasEmail = getStorage("userEmail") || getStorage("userName")?.includes("@");
if (!linked && !hasEmail) saveUserName(normalizedUserId);
if (!linked && !hasEmail) saveUserName(resolvedUserId);
}
return true;
} catch (err) {
@@ -570,7 +575,7 @@ export default function HomeClient() {
return false;
}
},
[recoverLinkedVipSession, savePaidType, saveUserName]
[recoverLinkedVipSession, resolveVipLookupUserId, savePaidType, saveUserName]
);
const checkPaymentFromPB = checkVerifyByUserId;
@@ -740,9 +745,10 @@ export default function HomeClient() {
// 后台悄悄校验:仅当服务端明确返回「非 VIP」才清本地弱网/异常/uncertain 一律保留(避免微信内误踢)
const verifyInBackground = async () => {
const isAnonymous = /^user\d+$/.test(localUserId);
const lookupUserId = resolveVipLookupUserId(localUserId);
const isAnonymous = /^user\d+$/.test(lookupUserId);
const probe = isAnonymous
? await probeCheckByUserId(localUserId)
? await probeCheckByUserId(lookupUserId)
: await probeSessionVip();
if (probe !== "no") {
return;

View File

@@ -13,6 +13,7 @@ import {
type PayjsVipResult = {
vip: boolean;
email?: string;
linkedUserId?: string;
};
const inflightUserChecks = new Map<string, Promise<PayjsVipResult | null>>();
@@ -108,6 +109,10 @@ async function checkVipFromPayjsapi(
typeof data?.email === "string" && data.email.trim()
? data.email.trim().toLowerCase()
: undefined,
linkedUserId:
typeof data?.linked_user_id === "string" && data.linked_user_id.trim()
? data.linked_user_id.trim()
: undefined,
};
console.log(
"[check-by-user] payjsapi response user_id=%s vip=%s email=%s",
@@ -214,6 +219,7 @@ export async function POST(request: NextRequest) {
if (payjsResult?.vip) {
vip = true;
email = payjsResult.email ?? null;
linkedUserId = payjsResult.linkedUserId;
vipSource = "payjsapi";
}
}