Hemmelig.app/client/api/account.js
bjarneo 0c86efd56c
refactor: use fastify vite for the dev server (#284)
* refactor: use fastify vite for the server

by doing this we do not need to have local hacks for the routes. No local proxy needed. Everything just works.

* fix: update the dockerfile build path

* fix: update package.json

* fix: fonts path
2024-03-11 13:43:20 +01:00

62 lines
1.3 KiB
JavaScript

import config from '../config';
export const getUser = async () => {
const data = await fetch(`${config.get('api.host')}/account/`, {
method: 'GET',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
});
if (data.status === 401) {
return {
statusCode: 401,
};
}
return data.json();
};
export const deleteUser = async () => {
const data = await fetch(`${config.get('api.host')}/account/delete`, {
method: 'POST',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
action: 'delete me',
}),
});
if (data.status === 401) {
return {
statusCode: 401,
};
}
return data.json();
};
export const updateUser = async (data) => {
const response = await fetch(`${config.get('api.host')}/account/update`, {
method: 'PUT',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ ...data, generated: false }),
});
const json = await response.json();
if (response.status === 401 && !json.type) {
return {
statusCode: response.status,
};
}
return json;
};