From ba7db775052a4afe61e057048697eee2ab338314 Mon Sep 17 00:00:00 2001 From: Blitblank Date: Sun, 22 Mar 2026 20:47:53 -0500 Subject: [PATCH] fix: fix routing based on token validation --- client/src/router/index.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/client/src/router/index.ts b/client/src/router/index.ts index 8591800..183b38a 100644 --- a/client/src/router/index.ts +++ b/client/src/router/index.ts @@ -8,6 +8,8 @@ import ItemsList from "../pages/ItemsList.vue"; import ItemForm from "../pages/ItemForm.vue"; import index from "../pages/index.vue"; +import { authStorage } from "../api/axios.ts" + // link path to the page component const routes = [ { path: "/", component: index }, @@ -26,24 +28,13 @@ const router = createRouter({ // intercept before routing router.beforeEach((to, from, next) => { - const token = localStorage.getItem("token"); + const token: string | null = authStorage.getAccessToken(); if(to.meta.requiresAuth && !token) { // if the page requires use to be signed in, they must have at least a token set next("/login"); } else { next(); } - // TODO: if they have a token, but invalid, it will still send them to the page (the api will catch non-authorized though) - // maybe have a "validate token" from the api and refresh it if valid - /* - } else { - bool authorizedUser = authApi.refreshToken(token); - if(authorizedUser) { - next(); - } else { - next("/login"); - } - } - */ + }); export default router;