From 004a1c07ed7f8030d59ff6d5cca6f2df34230ff9 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 17 Sep 2022 14:29:22 +0100 Subject: [PATCH] Automatically logout if a GET endpoint returns that a session is expired --- chartered-frontend/src/stores/auth.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/chartered-frontend/src/stores/auth.ts b/chartered-frontend/src/stores/auth.ts index 77e6295..9bddc61 100644 --- a/chartered-frontend/src/stores/auth.ts +++ a/chartered-frontend/src/stores/auth.ts @@ -1,6 +1,5 @@ import { get, writable } from 'svelte/store'; import { goto } from '$app/navigation'; -import { getErrorMessage } from '../util'; /** * The base URL of the chartered-web instance @@ -79,14 +78,7 @@ currentAuth.expires = Date.parse(json.expires); auth.set(currentAuth); } catch (e) { - // if the user's token is invalid for whatever reason after trying to refresh it, - // we should log them out. otherwise, we don't really know how to handle the error, - // and we should just print the error out to the console - if (getErrorMessage(e) === 'Expired auth token') { - auth.set(null); - } else { - console.error('Failed to extend user session', e); - } + console.error('Failed to extend user session', e); } } @@ -200,7 +192,10 @@ const json: T & Error = await result.json(); // TODO: handle 404s - if (json.error) { + if (json.error === 'Expired auth token') { + auth.set(null); + throw new Error(json.error); + } else if (json.error) { throw new Error(json.error); } -- rgit 0.1.3