start user page
This commit is contained in:
parent
90205a1243
commit
27cec4e77e
17 changed files with 401 additions and 82 deletions
|
@ -1,11 +1,13 @@
|
|||
import type { APIError } from "./entities";
|
||||
|
||||
export async function fetchAPI<T>(
|
||||
export async function apiFetch<T>(
|
||||
path: string,
|
||||
{ method, body, token }: { method?: string; body?: any; token?: string },
|
||||
) {
|
||||
const resp = await fetch(`${process.env.ORIGIN}/api/v1${path}`, {
|
||||
method,
|
||||
const apiBase = typeof process !== "undefined" ? process.env.ORIGIN : "";
|
||||
|
||||
const resp = await fetch(`${apiBase}/api/v1${path}`, {
|
||||
method: method || "GET",
|
||||
headers: {
|
||||
...(token ? { Authorization: token } : {}),
|
||||
"Content-Type": "application/json",
|
||||
|
@ -17,3 +19,6 @@ export async function fetchAPI<T>(
|
|||
if (resp.status < 200 || resp.status >= 300) throw data as APIError;
|
||||
return data as T;
|
||||
}
|
||||
|
||||
export const apiFetchClient = async <T>(path: string, method: string = "GET", body: any = null) =>
|
||||
apiFetch<T>(path, { method, body, token: localStorage.getItem("pronouns-token") || undefined });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue