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