Skip to content
Snippets Groups Projects
Commit 0788fc65 authored by Titus Netland's avatar Titus Netland
Browse files

Fixed guard route

parent d11a848c
No related branches found
No related tags found
1 merge request!24Fixed guard route
Pipeline #176541 passed
...@@ -9,12 +9,11 @@ import NewPasswordView from "../views/NewPasswordView"; ...@@ -9,12 +9,11 @@ import NewPasswordView from "../views/NewPasswordView";
* login page and the register page will be accessible. * login page and the register page will be accessible.
*/ */
function guardRoute(to, from, next) { function guardRoute(to, from, next) {
var isAuthenticated = false; let isAuthenticated = store.state.user.token != null;
if (store.state.user.token != null) isAuthenticated = true;
else isAuthenticated = false;
if (isAuthenticated) { if (isAuthenticated) {
next(); // allow to enter route next(); // allow to enter route
} else { }
else {
next("/login"); // go to '/login'; next("/login"); // go to '/login';
} }
} }
...@@ -23,13 +22,11 @@ const routes = [ ...@@ -23,13 +22,11 @@ const routes = [
{ {
path: "/", //Endre før push path: "/", //Endre før push
name: "home", name: "home",
beforeEnter: guardRoute,
component: HomeView, component: HomeView,
}, },
{ {
path: "/about", path: "/about",
name: "about", name: "about",
beforeEnter: guardRoute,
component: () => import("../views/AboutView.vue"), component: () => import("../views/AboutView.vue"),
}, },
{ {
...@@ -58,7 +55,6 @@ const routes = [ ...@@ -58,7 +55,6 @@ const routes = [
path: "/searchItemList", path: "/searchItemList",
name: "searchItemList", name: "searchItemList",
component: () => import("../views/SearchItemListView.vue"), component: () => import("../views/SearchItemListView.vue"),
beforeEnter: guardRoute,
}, },
{ {
path: "/createNewGroup", path: "/createNewGroup",
...@@ -76,11 +72,13 @@ const routes = [ ...@@ -76,11 +72,13 @@ const routes = [
path: "/notifications", path: "/notifications",
name: "notifications", name: "notifications",
component: () => import("../views/NotificationView.vue"), component: () => import("../views/NotificationView.vue"),
beforeEnter: guardRoute,
}, },
{ {
path: "/messages", path: "/messages",
name: "messages", name: "messages",
component: () => import("../views/MessagesView.vue"), component: () => import("../views/MessagesView.vue"),
beforeEnter: guardRoute,
}, },
]; ];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment