trial log, profile fixes

This commit is contained in:
2026-04-24 16:11:56 +07:00
parent 24e3a6de44
commit 0dc6562dd2
4 changed files with 62 additions and 67 deletions
+10 -7
View File
@@ -7,17 +7,13 @@ export const fetchProfile = async () => {
if (!token) throw new Error("No token found");
const res = await fetch(`${API_BASE}/me`, {
headers: {
Authorization: `Bearer ${token}`,
},
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) throw new Error("Failed to fetch profile");
return res.json();
};
// Существующий код...
export const submitHackResult = async (score: number) => {
const token = localStorage.getItem(TOKEN_KEY);
if (!token) throw new Error("No token found");
@@ -35,13 +31,17 @@ export const submitHackResult = async (score: number) => {
return res.json();
};
// 🔥 ИСПРАВЛЕНО: Правильный парсинг ошибки Триала
export const activateTrial = async () => {
const token = localStorage.getItem(TOKEN_KEY);
const res = await fetch(`${API_BASE}/trial`, {
method: "POST",
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) throw new Error(await res.text());
if (!res.ok) {
const errData = await res.json().catch(() => ({}));
throw new Error(errData.error || res.statusText || "Activation failed");
}
return res.json();
};
@@ -55,6 +55,9 @@ export const buySubscription = async (plan: string) => {
},
body: JSON.stringify({ plan }),
});
if (!res.ok) throw new Error(await res.text());
if (!res.ok) {
const errData = await res.json().catch(() => ({}));
throw new Error(errData.error || res.statusText || "Purchase failed");
}
return res.json();
};