Page logs you out if you arent logged in correctly

This commit is contained in:
sprechtl 2022-09-26 01:02:45 +02:00
parent 57eef24ca8
commit 23699abd68
2 changed files with 47 additions and 0 deletions

View file

@ -1,3 +1,21 @@
/**
* Capitalises first letter of string.
* @param str
*/
export function capitalizeFirstLetter(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
/**
* Fetches with applied bearer token.
* @param endpoint ex.: /users/me
* @param jwt Java Web Token used to authorize
* @param baseUrl Base Url of request
*/
export async function bearerFetch(endpoint: string, jwt: string, baseUrl: string = "http://localhost:1337/api") {
return await fetch(baseUrl + endpoint, {
headers: {
Authorization: `Bearer ${jwt}`
}
});
}