Public Access
refactor(auth): send login token through apiFetch
All authenticated calls now use apiFetch, and only utils/auth.js touches the stored token. The cookie login can then change these two files instead of every page.
This commit is contained in:
1 parent
085fcf15a4
commit
5ff8d48c53
18 files changed
+127
-70
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import {apiFetch} from './api.js';
|
||||
|
||||
export const GAME_STATUSES = ['BACKLOG', 'PLAYING', 'FINISHED', 'COMPLETED', 'DROPPED'];
|
||||
export const GAME_PRIORITIES = ['HIGH', 'MEDIUM', 'LOW'];
|
||||
|
||||
@@ -19,9 +21,9 @@ export const toBacklogRequest = ({status, rating, notes, priority}) => ({
|
||||
* @param entry a backlog entry in request form, see toBacklogRequest
|
||||
*/
|
||||
export const saveBacklogEntry = (appid, entry) =>
|
||||
fetch(`${import.meta.env.VITE_CORE_API_URL}/api/library/games/${appid}/backlog`, {
|
||||
apiFetch(`${import.meta.env.VITE_CORE_API_URL}/api/library/games/${appid}/backlog`, {
|
||||
method: 'PUT',
|
||||
headers: {'Authorization': `Bearer ${localStorage.getItem('tbp_jwt')}`, 'Content-Type': 'application/json'},
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(entry),
|
||||
});
|
||||
|
||||
@@ -29,9 +31,9 @@ export const saveBacklogEntry = (appid, entry) =>
|
||||
* PUT /api/library/games/{appid}/status. The caller handles the response status.
|
||||
*/
|
||||
export const saveGameStatus = (appid, status) =>
|
||||
fetch(`${import.meta.env.VITE_CORE_API_URL}/api/library/games/${appid}/status`, {
|
||||
apiFetch(`${import.meta.env.VITE_CORE_API_URL}/api/library/games/${appid}/status`, {
|
||||
method: 'PUT',
|
||||
headers: {'Authorization': `Bearer ${localStorage.getItem('tbp_jwt')}`, 'Content-Type': 'application/json'},
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({status}),
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user