Automatically logout if a GET endpoint returns that a session is expired
Diff
chartered-frontend/src/stores/auth.ts | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
@@ -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 (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();
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);
}