route middleware And Login

This commit is contained in:
saeid_01
2019-04-15 10:40:07 +04:30
parent 9f2acb855c
commit 8986f934a3
11 changed files with 120 additions and 72 deletions
+19 -19
View File
@@ -20,7 +20,7 @@ function route (options) {
let path = options.path;
let view = options.view;
let name = options.name;
let meta = (path.meta) ? path.meta : '';
let meta = (options.meta) ? options.meta : '';
return {
name: name || view,
path,
@@ -56,17 +56,17 @@ router.beforeEach((to, from, next) => {
const isPublic = to.matched.some(record => record.meta.public);
const onlyWhenLoggedOut = to.matched.some(record => record.meta.onlyWhenLoggedOut);
const loggedIn = !!TokenService.getToken();
// if (!isPublic && !loggedIn) {
// return next({
// path:'/login',
// query: {redirect: to.fullPath} // Store the full path to redirect the user to after login
// });
// }
if (!isPublic && !loggedIn) {
return next({
path:'/login',
query: {redirect: to.fullPath} // Store the full path to redirect the user to after login
});
}
// Do not allow user to visit login page or register page if they are logged in
// if (loggedIn && onlyWhenLoggedOut) {
// return next('/')
// }
if (loggedIn && onlyWhenLoggedOut) {
return next('/')
}
next();
});
@@ -74,14 +74,14 @@ router.beforeEach((to, from, next) => {
// Bootstrap Analytics
// Set in .env
// https://github.com/MatteoGabriele/vue-analytics
if (process.env.GOOGLE_ANALYTICS) {
Vue.use(VueAnalytics, {
id: process.env.GOOGLE_ANALYTICS,
router,
autoTracking: {
page: process.env.NODE_ENV !== 'development'
}
})
}
// if (process.env.GOOGLE_ANALYTICS) {
// Vue.use(VueAnalytics, {
// id: process.env.GOOGLE_ANALYTICS,
// router,
// autoTracking: {
// page: process.env.NODE_ENV !== 'development'
// }
// })
// }
export default router