From b1d994a0ff7f15271fc07e12ada94733ac277bbf Mon Sep 17 00:00:00 2001 From: Henry Dollman Date: Mon, 22 Jul 2024 11:05:14 -0400 Subject: [PATCH] verify auth if error fetching systems --- hub/site/src/lib/utils.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hub/site/src/lib/utils.ts b/hub/site/src/lib/utils.ts index 48942f5..b454333 100644 --- a/hub/site/src/lib/utils.ts +++ b/hub/site/src/lib/utils.ts @@ -26,15 +26,23 @@ export async function copyToClipboard(content: string) { }) } } - -export const updateSystemList = () => { - pb.collection('systems') - .getFullList({ sort: '+name' }) - .then((records) => { - $systems.set(records) +const verifyAuth = () => { + pb.collection('users') + .authRefresh() + .catch(() => { + pb.authStore.clear() }) } +export const updateSystemList = async () => { + try { + const records = await pb.collection('systems').getFullList({ sort: '+name' }) + $systems.set(records) + } catch (e) { + verifyAuth() + } +} + export const updateAlerts = () => { pb.collection('alerts') .getFullList({ fields: 'id,name,system' })