This commit is contained in:
eric
2026-03-27 19:22:37 -05:00
parent 3eb0334114
commit e1ed5a56dc
4 changed files with 124 additions and 60 deletions

View File

@@ -20,6 +20,8 @@ type UserCheckPayload = {
ok: boolean;
vip: boolean;
alreadyLinked: boolean;
/** 服务端异常/超时时为 true前端勿据此清空本地已登录 VIP */
uncertain?: boolean;
email?: string;
linkedUserId?: string;
};
@@ -292,18 +294,25 @@ export async function POST(request: NextRequest) {
};
} catch (error) {
console.error("[check-by-user] failed:", error);
// 接口容错:即使 PB 回退失败,也不抛 500 给前端
return { ok: true, vip: false, alreadyLinked: false };
// 勿伪装成「确定非 VIP」否则微信/H5 弱网会误清本地态
return {
ok: false,
vip: false,
alreadyLinked: false,
uncertain: true,
};
}
})();
inflightUserRequests.set(userId, task);
try {
const payload = await task;
userCheckResultCache.set(userId, {
payload,
expiresAt: Date.now() + USER_CHECK_CACHE_TTL_MS,
});
if (!payload.uncertain) {
userCheckResultCache.set(userId, {
payload,
expiresAt: Date.now() + USER_CHECK_CACHE_TTL_MS,
});
}
return NextResponse.json(payload);
} finally {
inflightUserRequests.delete(userId);

View File

@@ -86,6 +86,10 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ ok: true, vip: false });
} catch {
return NextResponse.json({ ok: true, vip: false });
return NextResponse.json({
ok: true,
vip: false,
uncertain: true,
});
}
}