feat(frontend): incomplete port to next.js
This commit is contained in:
parent
b9c30379ee
commit
eec01dc070
50 changed files with 2874 additions and 3163 deletions
28
frontend/lib/fetch.ts
Normal file
28
frontend/lib/fetch.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import type { APIError } from "./types";
|
||||
|
||||
export default async function fetchAPI<T>(
|
||||
path: string,
|
||||
method = "GET",
|
||||
body: any = null
|
||||
) {
|
||||
let headers = {};
|
||||
const token = localStorage.getItem("pronouns-token");
|
||||
if (token) {
|
||||
headers = {
|
||||
Authorization: token,
|
||||
};
|
||||
}
|
||||
|
||||
const resp = await fetch(`/api/v1${path}`, {
|
||||
method,
|
||||
headers: {
|
||||
...headers,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: body ? JSON.stringify(body) : null,
|
||||
});
|
||||
|
||||
const data = await resp.json();
|
||||
if (resp.status !== 200) throw data as APIError;
|
||||
return data as T;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue