From fb0b3ff9bc39de6c6dfeefd09bdf5be311fb1118 Mon Sep 17 00:00:00 2001 From: ansengarvin <45224464+ansengarvin@users.noreply.github.com> Date: Sun, 25 Feb 2024 19:36:04 -0800 Subject: [PATCH] Added ability to set and clear token headers from front end --- frontend/src/lib/backend.ts | 13 +++++++++++++ frontend/src/routes/Edit.svelte | 4 +++- frontend/src/routes/Login.svelte | 3 ++- frontend/src/routes/Upload.svelte | 3 ++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/backend.ts b/frontend/src/lib/backend.ts index a9fc598d..ec2f25bd 100644 --- a/frontend/src/lib/backend.ts +++ b/frontend/src/lib/backend.ts @@ -1,6 +1,19 @@ export * from "./openapi"; export { DefaultService as Backend } from "./openapi"; import { OpenAPI } from "./openapi"; +import Cookies from "js-cookie"; export const BACKEND_URL = "http://localhost:8000"; OpenAPI.BASE = BACKEND_URL; + +// Sets the token header to the stored authentication token from the cookie +export function setToken() { + console.log("Setting Token") + OpenAPI.TOKEN = Cookies.get("auth") +} + +// Sets the token header to nothing. +export function clearToken() { + console.log("Clearing token.") + OpenAPI.TOKEN = undefined +} diff --git a/frontend/src/routes/Edit.svelte b/frontend/src/routes/Edit.svelte index 0a23cfad..0c22fee9 100644 --- a/frontend/src/routes/Edit.svelte +++ b/frontend/src/routes/Edit.svelte @@ -1,5 +1,5 @@