s''
This commit is contained in:
@@ -110,34 +110,23 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
const payjsResult = await checkVipFromPayjsapi(request, userId);
|
||||
let vip = !!payjsResult?.vip;
|
||||
let email = payjsResult?.email ?? null;
|
||||
let payjsResult: PayjsVipResult | null = null;
|
||||
let vip = false;
|
||||
let email: string | null = null;
|
||||
let linkedUserId: string | undefined;
|
||||
let vipFromSite = false;
|
||||
let vipFromPayments = false;
|
||||
let vipSource = vip ? "payjsapi" : "none";
|
||||
|
||||
try {
|
||||
if (vip) {
|
||||
console.log(
|
||||
"[check-by-user] hit payjsapi user_id=%s alreadyLinked=%s",
|
||||
userId,
|
||||
!!email
|
||||
);
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
vip: true,
|
||||
alreadyLinked: !!email,
|
||||
email: email ?? undefined,
|
||||
});
|
||||
}
|
||||
|
||||
const adminToken = await getAdminToken().catch((error) => {
|
||||
console.error("[check-by-user] getAdminToken failed:", error);
|
||||
return null;
|
||||
});
|
||||
if (!adminToken) {
|
||||
payjsResult = await checkVipFromPayjsapi(request, userId);
|
||||
vip = !!payjsResult?.vip;
|
||||
email = payjsResult?.email ?? null;
|
||||
console.error("[check-by-user] missing PocketBase admin token, fallback to payjs result");
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
@@ -167,6 +156,16 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
// PB 未命中再请求 payjsapi,避免每次都先走远端网络
|
||||
if (!vip) {
|
||||
payjsResult = await checkVipFromPayjsapi(request, userId);
|
||||
if (payjsResult?.vip) {
|
||||
vip = true;
|
||||
email = payjsResult.email ?? null;
|
||||
vipSource = "payjsapi";
|
||||
}
|
||||
}
|
||||
|
||||
if (isAnonymousUserId(userId)) {
|
||||
const linkRecord = await findVipEmailLinkByAnonymousUserId(adminToken, userId);
|
||||
const linkEmail =
|
||||
|
||||
Reference in New Issue
Block a user