's'
This commit is contained in:
@@ -8,9 +8,8 @@ import {
|
||||
getDeviceFromEnv,
|
||||
} from "@/app/lib/payment";
|
||||
import { usePayStatusPoll } from "@/app/lib/payment/usePayStatusPoll";
|
||||
import type { PayEnv } from "@/app/lib/payment";
|
||||
import AuthModal from "@/app/components/AuthModal";
|
||||
import { apiUrl } from "@/app/lib/api-client";
|
||||
import { apiFetch, fetchAuthMe } from "@/app/lib/api-client";
|
||||
|
||||
const genderOptions = ["男", "女"];
|
||||
const singleOptions = ["单身", "恋爱中", "已婚"];
|
||||
@@ -55,7 +54,6 @@ export default function JoinPage() {
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [payRedirecting, setPayRedirecting] = useState(false);
|
||||
const [payEnv, setPayEnv] = useState<PayEnv | null>(null);
|
||||
const [authOpen, setAuthOpen] = useState(false);
|
||||
const [pendingSubmit, setPendingSubmit] = useState(false);
|
||||
const [isAlreadyRecorded, setIsAlreadyRecorded] = useState(false);
|
||||
@@ -67,14 +65,13 @@ export default function JoinPage() {
|
||||
}
|
||||
const checkExisting = async () => {
|
||||
try {
|
||||
const meRes = await fetch(apiUrl("/api/auth/me"), { credentials: "include" });
|
||||
const meData = await meRes.json().catch(() => ({}));
|
||||
if (!meRes.ok || !meData?.user) {
|
||||
return;
|
||||
}
|
||||
const statusRes = await fetch(apiUrl("/api/join/status"), { credentials: "include", cache: "no-store" });
|
||||
const statusData = await statusRes.json().catch(() => ({}));
|
||||
if (statusRes.ok && statusData?.hasRecord && statusData?.isComplete) {
|
||||
const meData = await fetchAuthMe();
|
||||
if (!meData?.user) return;
|
||||
const statusData = await apiFetch<{ hasRecord?: boolean; isComplete?: boolean }>(
|
||||
"/api/join/status",
|
||||
{ cache: "no-store" }
|
||||
);
|
||||
if (statusData?.hasRecord && statusData?.isComplete) {
|
||||
setIsAlreadyRecorded(true);
|
||||
setSubmitted(true);
|
||||
}
|
||||
@@ -94,11 +91,6 @@ export default function JoinPage() {
|
||||
window.location.replace(url);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
setPayEnv(getPayEnv());
|
||||
}, []);
|
||||
|
||||
const set = (key: keyof FormData, value: string) =>
|
||||
setForm((prev) => ({ ...prev, [key]: value }));
|
||||
|
||||
@@ -106,14 +98,11 @@ export default function JoinPage() {
|
||||
setError(null);
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const res = await fetch(apiUrl("/api/join"), {
|
||||
const data = await apiFetch<{ ok?: boolean; user_id?: string; error?: string }>("/api/join", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ ...form, media: media?.url }),
|
||||
credentials: "include",
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok || !data?.ok) {
|
||||
if (!data?.ok) {
|
||||
throw new Error(data?.error || "提交失败,请稍后重试");
|
||||
}
|
||||
const userId = data.user_id;
|
||||
@@ -122,8 +111,7 @@ export default function JoinPage() {
|
||||
return;
|
||||
}
|
||||
// 再次确认 VIP,防止 handleAuthSuccess 等路径绕过
|
||||
const vipRes2 = await fetch(apiUrl("/api/vip/check"), { credentials: "include", cache: "no-store" });
|
||||
const vipData2 = await vipRes2.json();
|
||||
const vipData2 = await apiFetch<{ vip?: boolean }>("/api/vip/check", { cache: "no-store" });
|
||||
if (vipData2?.vip) {
|
||||
setIsVipSubmit(true);
|
||||
setSubmitted(true);
|
||||
@@ -153,15 +141,13 @@ export default function JoinPage() {
|
||||
|
||||
const handleSubmit = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
const meRes = await fetch(apiUrl("/api/auth/me"), { credentials: "include" });
|
||||
const meData = await meRes.json();
|
||||
const meData = await fetchAuthMe();
|
||||
if (!meData?.user) {
|
||||
setPendingSubmit(true);
|
||||
setAuthOpen(true);
|
||||
return;
|
||||
}
|
||||
const vipRes = await fetch(apiUrl("/api/vip/check"), { credentials: "include", cache: "no-store" });
|
||||
const vipData = await vipRes.json();
|
||||
const vipData = await apiFetch<{ vip?: boolean }>("/api/vip/check", { cache: "no-store" });
|
||||
if (vipData?.vip) {
|
||||
setIsVipSubmit(true);
|
||||
}
|
||||
@@ -394,12 +380,11 @@ export default function JoinPage() {
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
const res = await fetch(apiUrl("/api/upload-media"), {
|
||||
method: "POST",
|
||||
body: fd,
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok || !data?.ok) {
|
||||
const data = await apiFetch<{ ok?: boolean; url?: string; error?: string }>(
|
||||
"/api/upload-media",
|
||||
{ method: "POST", body: fd }
|
||||
);
|
||||
if (!data?.ok) {
|
||||
throw new Error(data?.error || "上传失败");
|
||||
}
|
||||
setMedia((m) => (m ? { ...m, url: data.url } : null));
|
||||
|
||||
Reference in New Issue
Block a user