From 4c43a00e884b3eba06d9d2931dfdad3a6bae5a9d Mon Sep 17 00:00:00 2001 From: jj Date: Sun, 20 Oct 2024 11:46:09 +0000 Subject: [PATCH] web/api/session: replace writable with normal variable --- web/src/lib/api/session.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/web/src/lib/api/session.ts b/web/src/lib/api/session.ts index f7974393..f627b6f2 100644 --- a/web/src/lib/api/session.ts +++ b/web/src/lib/api/session.ts @@ -1,12 +1,11 @@ import turnstile from "$lib/api/turnstile"; -import { writable, get } from "svelte/store"; import { currentApiURL } from "$lib/api/api-url"; import type { CobaltSession, CobaltErrorResponse, CobaltSessionResponse } from "$lib/types/api"; -const cachedSession = writable(); +let cache: CobaltSession | undefined; -export const requestSession = async() => { +export const requestSession = async () => { const apiEndpoint = `${currentApiURL()}/session`; let requestHeaders = {}; @@ -43,7 +42,6 @@ export const requestSession = async() => { export const getSession = async () => { const currentTime = () => Math.floor(new Date().getTime() / 1000); - const cache = get(cachedSession); if (cache?.token && cache?.exp - 2 > currentTime()) { return cache; @@ -60,7 +58,7 @@ export const getSession = async () => { if (!("status" in newSession)) { newSession.exp = currentTime() + newSession.exp; - cachedSession.set(newSession); + cache = newSession; } return newSession; }