Rework authentication

This commit is contained in:
Aslan 2026-01-01 17:06:31 +01:00
parent a85330e8cf
commit c07d33bcc9
17 changed files with 317 additions and 128 deletions

View file

@ -2,6 +2,32 @@ import config from "../src/config.json" with { type: "json" };
const url = `http://localhost:${config.port}/api/v1`;
const apiCookie = async (endpoint, request) => {
const response = await fetch(`${url}/${endpoint}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(request),
});
const responseCookie = response.headers.getSetCookie().at(0) ?? "";
return [await response.json(), responseCookie];
};
const apiToken = async (endpoint, cookie) => {
const response = await fetch(`${url}/${endpoint}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Cookie: cookie,
},
});
return await response.json();
};
const apiGet = async (endpoint, token) => {
const response = await fetch(`${url}/${endpoint}`, {
method: "GET",
@ -53,4 +79,4 @@ const apiDelete = async (endpoint, request, token) => {
return await response.json();
};
export { apiGet, apiPost, apiPatch, apiDelete };
export { apiCookie, apiToken, apiGet, apiPost, apiPatch, apiDelete };