fix: fix routing based on token validation
All checks were successful
Build and Deploy Frontend / build-and-deploy (push) Successful in 7s
All checks were successful
Build and Deploy Frontend / build-and-deploy (push) Successful in 7s
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user