This commit is contained in:
eric
2026-06-07 22:50:42 -05:00
parent d27807e504
commit 6d479c9f94
23 changed files with 435 additions and 277 deletions

View File

@@ -8,8 +8,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, syncAuthSession } from "@/app/lib/api-client";
import { googleLogin } from "@/app/lib/pocketbase";
import GoogleLoginButton from "./GoogleLoginButton";
@@ -39,16 +39,7 @@ export default function JoinModal({ isOpen, onClose, initialEmail = "", vipOnly
const saveAuth = useCallback(async (token: string, record: Record<string, unknown>) => {
const { pbSaveAuth } = await import("@/app/lib/pocketbase");
pbSaveAuth(token, record as { id: string; email: string; [key: string]: unknown });
try {
await fetch(apiUrl("/api/auth/sync-session"), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token, record }),
credentials: "include",
});
} catch {
/* local auth is already saved; backend cookie will be retried by the navbar */
}
await syncAuthSession(token, record);
if (typeof window !== "undefined") {
window.dispatchEvent(new CustomEvent("auth:updated"));
}
@@ -82,14 +73,17 @@ export default function JoinModal({ isOpen, onClose, initialEmail = "", vipOnly
setError(null);
setLoading(true);
try {
const res = await fetch(apiUrl("/api/meetup/ensure-user"), {
const data = await apiFetch<{
ok?: boolean;
token?: string;
record?: Record<string, unknown>;
user_id?: string;
error?: string;
}>("/api/meetup/ensure-user", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email: em }),
credentials: "include",
});
const data = await res.json();
if (!res.ok || !data?.ok) {
if (!data?.ok) {
throw new Error(data?.error || (locale === "zh" ? "操作失败" : "Operation failed"));
}
await saveAuth(data.token, data.record);