File size: 568 Bytes
e394370 e6f1924 e394370 e6f1924 e394370 e6f1924 e394370 e6f1924 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | function getCookie(name: string) {
if (typeof document === "undefined") return null;
const match = document.cookie
.split("; ")
.find((row) => row.startsWith(name + "="));
return match?.split("=")[1] ?? null;
}
export async function authFetch(
url: string,
options?: RequestInit
) {
const token = getCookie("auth_token");
return fetch(url, {
...options,
credentials: "include",
headers: {
"Content-Type": "application/json",
...(token && { Authorization: `Bearer ${token}` }),
...options?.headers,
},
});
} |