This commit is contained in:
eric
2026-03-13 04:41:51 -05:00
parent 37d0883ce9
commit a193fe4d45
22 changed files with 1119 additions and 468 deletions

View File

@@ -18,14 +18,9 @@ export function useAuthAndVip(): AuthAndVipState {
const refetch = useCallback(async (): Promise<{ user: { id: string; email: string } | null; vip: boolean }> => {
setLoading(true);
try {
const [meRes, vipRes] = await Promise.all([
fetch("/api/auth/me", { credentials: "include" }),
fetch("/api/vip/check", { credentials: "include" }),
]);
const meRes = await fetch("/api/auth/me", { credentials: "include" });
const meData = await meRes.json();
const vipData = await vipRes.json();
let newUser = meData?.user ?? null;
let newVip = vipData?.vip === true;
if (!newUser) {
const storedUser = getStoredUser();
@@ -45,6 +40,13 @@ export function useAuthAndVip(): AuthAndVipState {
}
}
let newVip = false;
if (newUser?.email) {
const vipRes = await fetch(`/api/vip/check?email=${encodeURIComponent(newUser.email)}`, { credentials: "include" });
const vipData = await vipRes.json();
newVip = vipData?.vip === true;
}
setUser(newUser);
setVip(newVip);
return { user: newUser, vip: newVip };