's'
This commit is contained in:
@@ -3,6 +3,15 @@ import { getAdminToken } from "@/app/lib/pocketbase/admin";
|
|||||||
import { getPocketBaseConfig } from "@/config/services.config";
|
import { getPocketBaseConfig } from "@/config/services.config";
|
||||||
import { getSalonApi } from "@/app/lib/salonApi";
|
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 = {
|
const empty = {
|
||||||
hasRecord: false,
|
hasRecord: false,
|
||||||
record: null,
|
record: null,
|
||||||
@@ -65,7 +74,7 @@ async function getPocketBaseJoinByWechat(wechatId: string) {
|
|||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
const wechatId = request.nextUrl.searchParams.get("wechat_id")?.trim();
|
const wechatId = request.nextUrl.searchParams.get("wechat_id")?.trim();
|
||||||
if (!wechatId) {
|
if (!wechatId) {
|
||||||
return NextResponse.json(empty);
|
return NextResponse.json(empty, { headers: NO_CACHE_HEADERS });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -75,7 +84,7 @@ export async function GET(request: NextRequest) {
|
|||||||
{ timeoutMs: 6000 }
|
{ timeoutMs: 6000 }
|
||||||
);
|
);
|
||||||
if (status === 200 && data && typeof data === "object") {
|
if (status === 200 && data && typeof data === "object") {
|
||||||
return NextResponse.json(data);
|
return NextResponse.json(data, { headers: NO_CACHE_HEADERS });
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
/* salonapi 不可用,回退直连 PocketBase */
|
/* salonapi 不可用,回退直连 PocketBase */
|
||||||
@@ -83,8 +92,8 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
const pbData = await getPocketBaseJoinByWechat(wechatId);
|
const pbData = await getPocketBaseJoinByWechat(wechatId);
|
||||||
if (pbData) {
|
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 });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export default function MyRegistrationStatus() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLoading(true);
|
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((r) => r.json())
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
if (d?.hasRecord) {
|
if (d?.hasRecord) {
|
||||||
@@ -83,10 +83,20 @@ export default function MyRegistrationStatus() {
|
|||||||
const onUpdate = () => {
|
const onUpdate = () => {
|
||||||
if (!cancelled) fetchStatus();
|
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);
|
window.addEventListener("vip:updated", onUpdate);
|
||||||
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
||||||
|
window.addEventListener("pageshow", onPageShow);
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
window.removeEventListener("vip:updated", onUpdate);
|
window.removeEventListener("vip:updated", onUpdate);
|
||||||
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
||||||
|
window.removeEventListener("pageshow", onPageShow);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ export default function JoinPage() {
|
|||||||
setError(null);
|
setError(null);
|
||||||
setCheckingWechat(true);
|
setCheckingWechat(true);
|
||||||
try {
|
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",
|
cache: "no-store",
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -295,7 +295,7 @@ export default function JoinPage() {
|
|||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
|
|
||||||
try {
|
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();
|
const checkData = await checkRes.json();
|
||||||
if (checkData?.hasRecord) {
|
if (checkData?.hasRecord) {
|
||||||
setError("该微信号已报名,请勿重复提交");
|
setError("该微信号已报名,请勿重复提交");
|
||||||
@@ -439,7 +439,7 @@ export default function JoinPage() {
|
|||||||
if (pendingId && !params.has("paid") && stored && WECHAT_REGEX.test(stored)) {
|
if (pendingId && !params.has("paid") && stored && WECHAT_REGEX.test(stored)) {
|
||||||
setWechat(stored);
|
setWechat(stored);
|
||||||
let cancelled = false;
|
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((res) => res.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user