's'
This commit is contained in:
@@ -9,8 +9,8 @@ import {
|
||||
redirectToPay,
|
||||
getDeviceFromEnv,
|
||||
} from "@/app/lib/payment";
|
||||
import type { PayChannel, PayEnv } from "@/app/lib/payment";
|
||||
import { apiUrl } from "@/app/lib/api-client";
|
||||
import type { PayChannel } from "@/app/lib/payment";
|
||||
import { apiFetch, fetchAuthMe, syncAuthSession } from "@/app/lib/api-client";
|
||||
import { mediaUrl } from "@/app/lib/media";
|
||||
import { avatarForIndex } from "@/app/data/avatars";
|
||||
|
||||
@@ -74,13 +74,8 @@ export default function HeroSection() {
|
||||
|
||||
useEffect(() => {
|
||||
const checkAuth = async () => {
|
||||
try {
|
||||
const res = await fetch(apiUrl("/api/auth/me"), { credentials: "include" });
|
||||
const data = await res.json();
|
||||
setIsLoggedIn(!!data?.user);
|
||||
} catch {
|
||||
setIsLoggedIn(false);
|
||||
}
|
||||
const data = await fetchAuthMe();
|
||||
setIsLoggedIn(!!data?.user);
|
||||
};
|
||||
checkAuth();
|
||||
const onAuth = () => checkAuth();
|
||||
@@ -111,15 +106,12 @@ export default function HeroSection() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const checkRes = await fetch(apiUrl("/api/meetup/check-user"), {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ email: trimmed }),
|
||||
credentials: "include",
|
||||
});
|
||||
const checkData = await checkRes.json();
|
||||
if (!checkRes.ok || !checkData?.ok) {
|
||||
throw new Error(checkData?.error || checkData?.detail || (locale === "zh" ? "操作失败" : "Operation failed"));
|
||||
const checkData = await apiFetch<{ ok?: boolean; exists?: boolean; vip?: boolean; error?: string }>(
|
||||
"/api/meetup/check-user",
|
||||
{ method: "POST", body: JSON.stringify({ email: trimmed }) }
|
||||
);
|
||||
if (!checkData?.ok) {
|
||||
throw new Error(checkData?.error || (locale === "zh" ? "操作失败" : "Operation failed"));
|
||||
}
|
||||
if (checkData.exists) {
|
||||
checkUserCacheRef.current = { email: trimmed, data: { exists: true, vip: !!checkData.vip }, ts: Date.now() };
|
||||
@@ -138,28 +130,24 @@ export default function HeroSection() {
|
||||
isPrivateDevHost(window.location.hostname);
|
||||
let user_id = buildPendingUserId(trimmed);
|
||||
if (shouldPrecreateUser) {
|
||||
const ensureRes = await fetch(apiUrl("/api/meetup/ensure-user"), {
|
||||
const ensureData = await apiFetch<{
|
||||
ok?: boolean;
|
||||
user_id?: string;
|
||||
token?: string;
|
||||
record?: Record<string, unknown>;
|
||||
error?: string;
|
||||
}>("/api/meetup/ensure-user", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ email: trimmed }),
|
||||
credentials: "include",
|
||||
});
|
||||
const ensureData = await ensureRes.json();
|
||||
if (!ensureRes.ok || !ensureData?.ok || !ensureData?.user_id) {
|
||||
if (!ensureData?.ok || !ensureData?.user_id) {
|
||||
throw new Error(
|
||||
ensureData?.error ||
|
||||
ensureData?.detail ||
|
||||
(locale === "zh" ? "创建用户失败" : "Failed to create user")
|
||||
ensureData?.error || (locale === "zh" ? "创建用户失败" : "Failed to create user")
|
||||
);
|
||||
}
|
||||
user_id = String(ensureData.user_id).trim();
|
||||
if (ensureData?.token && ensureData?.record) {
|
||||
await fetch(apiUrl("/api/auth/sync-session"), {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ token: ensureData.token, record: ensureData.record }),
|
||||
credentials: "include",
|
||||
});
|
||||
await syncAuthSession(ensureData.token, ensureData.record);
|
||||
}
|
||||
}
|
||||
const returnUrl =
|
||||
|
||||
Reference in New Issue
Block a user