mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
28 lines
713 B
TypeScript
28 lines
713 B
TypeScript
import type { SubscriptionRecord } from "@sprint/shared";
|
|
import { getServerURL } from "@/lib/utils";
|
|
|
|
interface GetSubscriptionParams {
|
|
onSuccess?: (subscription: SubscriptionRecord | null) => void;
|
|
onError?: (error: string) => void;
|
|
}
|
|
|
|
export async function getSubscription({ onSuccess, onError }: GetSubscriptionParams) {
|
|
try {
|
|
const response = await fetch(`${getServerURL()}/subscription/get`, {
|
|
method: "GET",
|
|
credentials: "include",
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
onError?.(data.error || "Failed to fetch subscription");
|
|
return;
|
|
}
|
|
|
|
onSuccess?.(data.subscription);
|
|
} catch (error) {
|
|
onError?.("Network error");
|
|
}
|
|
}
|