Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronmacaron committed Oct 29, 2023
2 parents 519ab03 + a66f884 commit 86a61dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
18 changes: 12 additions & 6 deletions frontend/src/lib/api.ts
@@ -1,18 +1,24 @@
const DATABASE_URL = 'http://localhost:8080/';

function getToken() {
return 'Bearer ' + localStorage.getItem('token') ?? '';
}

function get(path: string) {
return fetch(DATABASE_URL + path, { method: 'GET' }).then((res) => {
if (!res.ok) {
throw res;
return fetch(DATABASE_URL + path, { method: 'GET', headers: { Atuhorization: getToken() } }).then(
(res) => {
if (!res.ok) {
throw res;
}
return res;
}
return res;
});
);
}

function post(path: string, body) {
return fetch(DATABASE_URL + path, {
method: 'POST',
headers: { 'content-type': 'application/json' },
headers: { 'content-type': 'application/json', Authorization: getToken() },
body: JSON.stringify(body)
}).then((res) => {
if (!res.ok) {
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/routes/events/join/[eventId]/+page.svelte
Expand Up @@ -30,10 +30,9 @@
async function createUser() {
try {
const response = await api.post('users/', { name: name });
const authorizationHeader = response.headers;
const json =await response.json();
console.log(json);
const json = await response.json();
const token = json.token;
localStorage.setItem("token", token);
// console.log(response);
// const bearerToken = authorizationHeader.split(' ');
} catch (e) {
Expand Down

0 comments on commit 86a61dd

Please sign in to comment.