This commit is contained in:
eric
2026-03-16 20:24:28 -05:00
parent c93eb7b2ee
commit 473fa1a1cf
3 changed files with 27 additions and 8 deletions

View File

@@ -3,6 +3,15 @@ import { getAdminToken } from "@/app/lib/pocketbase/admin";
import { getPocketBaseConfig } from "@/config/services.config";
import { getSalonApi } from "@/app/lib/salonApi";
/** 用户状态必须实时从数据库获取,禁止缓存 */
export const dynamic = "force-dynamic";
const NO_CACHE_HEADERS = {
"Cache-Control": "no-store, no-cache, must-revalidate, proxy-revalidate",
Pragma: "no-cache",
Expires: "0",
};
const empty = {
hasRecord: false,
record: null,
@@ -65,7 +74,7 @@ async function getPocketBaseJoinByWechat(wechatId: string) {
export async function GET(request: NextRequest) {
const wechatId = request.nextUrl.searchParams.get("wechat_id")?.trim();
if (!wechatId) {
return NextResponse.json(empty);
return NextResponse.json(empty, { headers: NO_CACHE_HEADERS });
}
try {
@@ -75,7 +84,7 @@ export async function GET(request: NextRequest) {
{ timeoutMs: 6000 }
);
if (status === 200 && data && typeof data === "object") {
return NextResponse.json(data);
return NextResponse.json(data, { headers: NO_CACHE_HEADERS });
}
} catch {
/* salonapi 不可用,回退直连 PocketBase */
@@ -83,8 +92,8 @@ export async function GET(request: NextRequest) {
const pbData = await getPocketBaseJoinByWechat(wechatId);
if (pbData) {
return NextResponse.json(pbData);
return NextResponse.json(pbData, { headers: NO_CACHE_HEADERS });
}
return NextResponse.json(empty);
return NextResponse.json(empty, { headers: NO_CACHE_HEADERS });
}

View File

@@ -52,7 +52,7 @@ export default function MyRegistrationStatus() {
return;
}
setLoading(true);
fetch(`/api/join/by-wechat?wechat_id=${encodeURIComponent(wechatId)}`)
fetch(`/api/join/by-wechat?wechat_id=${encodeURIComponent(wechatId)}&_=${Date.now()}`, { cache: "no-store" })
.then((r) => r.json())
.then((d) => {
if (d?.hasRecord) {
@@ -83,10 +83,20 @@ export default function MyRegistrationStatus() {
const onUpdate = () => {
if (!cancelled) fetchStatus();
};
const onVisibilityChange = () => {
if (document.visibilityState === "visible" && !cancelled) fetchStatus();
};
const onPageShow = (e: PageTransitionEvent) => {
if (e.persisted && !cancelled) fetchStatus();
};
window.addEventListener("vip:updated", onUpdate);
document.addEventListener("visibilitychange", onVisibilityChange);
window.addEventListener("pageshow", onPageShow);
return () => {
cancelled = true;
window.removeEventListener("vip:updated", onUpdate);
document.removeEventListener("visibilitychange", onVisibilityChange);
window.removeEventListener("pageshow", onPageShow);
};
}, []);

View File

@@ -167,7 +167,7 @@ export default function JoinPage() {
setError(null);
setCheckingWechat(true);
try {
const res = await fetch(`/api/join/by-wechat?wechat_id=${encodeURIComponent(w.trim())}`, {
const res = await fetch(`/api/join/by-wechat?wechat_id=${encodeURIComponent(w.trim())}&_=${Date.now()}`, {
cache: "no-store",
});
const data = await res.json();
@@ -295,7 +295,7 @@ export default function JoinPage() {
setSubmitting(true);
try {
const checkRes = await fetch(`/api/join/by-wechat?wechat_id=${encodeURIComponent(wechat.trim())}`, { cache: "no-store" });
const checkRes = await fetch(`/api/join/by-wechat?wechat_id=${encodeURIComponent(wechat.trim())}&_=${Date.now()}`, { cache: "no-store" });
const checkData = await checkRes.json();
if (checkData?.hasRecord) {
setError("该微信号已报名,请勿重复提交");
@@ -439,7 +439,7 @@ export default function JoinPage() {
if (pendingId && !params.has("paid") && stored && WECHAT_REGEX.test(stored)) {
setWechat(stored);
let cancelled = false;
fetch(`/api/join/by-wechat?wechat_id=${encodeURIComponent(stored)}`, { cache: "no-store" })
fetch(`/api/join/by-wechat?wechat_id=${encodeURIComponent(stored)}&_=${Date.now()}`, { cache: "no-store" })
.then((res) => res.json())
.then((data) => {
if (cancelled) return;