's'
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user