13 lines
588 B
TypeScript
13 lines
588 B
TypeScript
|
|
"use client";
|
||
|
|
import getPocketBase from "@/lib/pocketbase";
|
||
|
|
|
||
|
|
/** Browser-session authentication is distinct from the audit attribution header. */
|
||
|
|
export async function paymentFetch<T>(url: string, init?: RequestInit): Promise<T> {
|
||
|
|
const headers = new Headers(init?.headers);
|
||
|
|
headers.set("Authorization", `Bearer ${getPocketBase().authStore.token}`);
|
||
|
|
const response = await fetch(url, { ...init, headers, cache: "no-store" });
|
||
|
|
const result = await response.json();
|
||
|
|
if (!response.ok) throw new Error(result.error || `Request failed (${response.status})`);
|
||
|
|
return result as T;
|
||
|
|
}
|