This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import Vue from "vue";
|
||||
import Router from "vue-router";
|
||||
import Home from "./views/Home.vue";
|
||||
import { isLoggedIn, login, logout } from './utils/auth';
|
||||
//import { isLoggedIn, login, logout } from "./utils/auth";
|
||||
|
||||
Vue.use(Router);
|
||||
|
||||
@@ -9,30 +9,30 @@ export default new Router({
|
||||
mode: "history",
|
||||
base: process.env.BASE_URL,
|
||||
routes: [
|
||||
{
|
||||
path: "/",
|
||||
redirect: {
|
||||
name: "login"
|
||||
}
|
||||
},
|
||||
// {
|
||||
// path: "/",
|
||||
// redirect: {
|
||||
// name: "login"
|
||||
// }
|
||||
// },
|
||||
{
|
||||
path: "/login",
|
||||
name: "login",
|
||||
component: () =>
|
||||
import(/* webpackChunkName: "login" */ "./views/login.vue")
|
||||
},
|
||||
{
|
||||
path: "/secure",
|
||||
name: "secure",
|
||||
component: () =>
|
||||
import(/* webpackChunkName: "secure" */ "./views/secure.vue")
|
||||
},
|
||||
|
||||
// {
|
||||
// path: "/",
|
||||
// name: "home",
|
||||
// component: Home
|
||||
// path: "/secure",
|
||||
// name: "secure",
|
||||
// component: () =>
|
||||
// import(/* webpackChunkName: "secure" */ "./views/secure.vue")
|
||||
// },
|
||||
|
||||
{
|
||||
path: "/",
|
||||
name: "home",
|
||||
component: Home
|
||||
},
|
||||
{
|
||||
path: "/about",
|
||||
name: "about",
|
||||
@@ -45,34 +45,34 @@ export default new Router({
|
||||
]
|
||||
});
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
if(to.matched.some(record => record.meta.requiresAuth)) {
|
||||
if (localStorage.getItem('jwt') == null) {
|
||||
next({
|
||||
path: '/login',
|
||||
params: { nextUrl: to.fullPath }
|
||||
})
|
||||
} else {
|
||||
let user = JSON.parse(localStorage.getItem('user'))
|
||||
if(to.matched.some(record => record.meta.is_admin)) {
|
||||
if(user.is_admin == 1){
|
||||
next()
|
||||
}
|
||||
else{
|
||||
next({ name: 'userboard'})
|
||||
}
|
||||
}else {
|
||||
next()
|
||||
}
|
||||
}
|
||||
} else if(to.matched.some(record => record.meta.guest)) {
|
||||
if(localStorage.getItem('jwt') == null){
|
||||
next()
|
||||
}
|
||||
else{
|
||||
next({ name: 'userboard'})
|
||||
}
|
||||
}else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
// Router.beforeEach((to, from, next) => {
|
||||
// if(to.matched.some(record => record.meta.requiresAuth)) {
|
||||
// if (localStorage.getItem('jwt') == null) {
|
||||
// next({
|
||||
// path: '/login',
|
||||
// params: { nextUrl: to.fullPath }
|
||||
// })
|
||||
// } else {
|
||||
// let user = JSON.parse(localStorage.getItem('user'))
|
||||
// if(to.matched.some(record => record.meta.is_admin)) {
|
||||
// if(user.is_admin == 1){
|
||||
// next()
|
||||
// }
|
||||
// else{
|
||||
// next({ name: 'userboard'})
|
||||
// }
|
||||
// }else {
|
||||
// next()
|
||||
// }
|
||||
// }
|
||||
// } else if(to.matched.some(record => record.meta.guest)) {
|
||||
// if(localStorage.getItem('jwt') == null){
|
||||
// next()
|
||||
// }
|
||||
// else{
|
||||
// next({ name: 'userboard'})
|
||||
// }
|
||||
// }else {
|
||||
// next()
|
||||
// }
|
||||
// })
|
||||
|
||||
Reference in New Issue
Block a user