From f8465276e3d880bdc3f4af705873db6101b6faf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20P=C4=99dzich?= Date: Fri, 26 May 2023 15:01:35 +0200 Subject: [PATCH] Move loadUser error handling to the function itself --- src/composables/useAuth.ts | 6 ++++++ src/guards/auth.ts | 8 +------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/composables/useAuth.ts b/src/composables/useAuth.ts index 1bb91c9..0e9d2f9 100644 --- a/src/composables/useAuth.ts +++ b/src/composables/useAuth.ts @@ -29,6 +29,12 @@ export function useAuth() { const currentUser = await account.get(); user.value = currentUser; + } catch (error) { + if (import.meta.env.DEV) { + console.error(error); + } + + user.value = null; } finally { loadingUserFinished.value = true; } diff --git a/src/guards/auth.ts b/src/guards/auth.ts index 9b13dc4..2c5a1e6 100644 --- a/src/guards/auth.ts +++ b/src/guards/auth.ts @@ -8,13 +8,7 @@ export async function authGuard( ) { const { isLoggedIn, loadUser } = useAuth(); - try { - await loadUser(); - } catch (error) { - if (import.meta.env.DEV) { - console.error(error); - } - } + await loadUser(); if (!to.meta.authRequired || isLoggedIn.value) { return next();