Feature/Auth: implement user authentication #3

Merged
homeburger merged 48 commits from feature/auth into main 2026-03-22 20:52:22 -05:00
Showing only changes of commit ba7db77505 - Show all commits

View File

@@ -8,6 +8,8 @@ import ItemsList from "../pages/ItemsList.vue";
import ItemForm from "../pages/ItemForm.vue"; import ItemForm from "../pages/ItemForm.vue";
import index from "../pages/index.vue"; import index from "../pages/index.vue";
import { authStorage } from "../api/axios.ts"
// link path to the page component // link path to the page component
const routes = [ const routes = [
{ path: "/", component: index }, { path: "/", component: index },
@@ -26,24 +28,13 @@ const router = createRouter({
// intercept before routing // intercept before routing
router.beforeEach((to, from, next) => { 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 if(to.meta.requiresAuth && !token) { // if the page requires use to be signed in, they must have at least a token set
next("/login"); next("/login");
} else { } else {
next(); 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; export default router;