Skip to content

Commit

Permalink
fix: route unauth redirecting
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabil-Salah committed Aug 29, 2024
1 parent ed72533 commit 86e4c94
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ const routes: Array<RouteRecordRaw> = [
path: "/myflists",
name: "myflists",
component: UserFlist,
meta: { requireAuth: true },
meta: { requiresAuth: true },
},
{
path: "/create",
name: "create",
component: CreateFlist,
meta: { requiresAuth: true },
},
{
path: "/",
name: "home",
component: Home,
},
{
path: "/flists/:username/:id",
name: "previewflist",
component: PreviewFlist,
},
{
path: "/",
name: "home",
component: Home,
},
];

const router = createRouter({
Expand All @@ -42,7 +42,10 @@ const router = createRouter({

router.beforeEach((to, _, next) => {
const token: string | null = sessionStorage.getItem("token");
if (to.meta.requiresAuth && token === null) {
console.log(token);
console.log(to.meta.requiresAuth);
if (to.meta.requiresAuth && (token == null || token.length == 0)) {
console.log("ffej");
next({ name: "login" });
} else {
next();
Expand Down

0 comments on commit 86e4c94

Please sign in to comment.