start user page

This commit is contained in:
Sam 2023-03-11 01:36:30 +01:00
parent 90205a1243
commit 27cec4e77e
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
17 changed files with 401 additions and 82 deletions

View file

@ -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 });