mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange.git
synced 2026-08-27 00:04:10 +00:00
fix admin routes on vuejs
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import store from '~/store'
|
||||
|
||||
export default (to, from, next) => {
|
||||
if (store.getters['auth/user'].role !== 'admin') {
|
||||
console.log(store.getters['auth/role'])
|
||||
if (store.getters['auth/role'] !== 'admin') {
|
||||
next({ name: 'home' })
|
||||
} else {
|
||||
next()
|
||||
|
||||
@@ -3,7 +3,7 @@ import store from '~/store'
|
||||
export default async (to, from, next) => {
|
||||
if (!store.getters['auth/check']) {
|
||||
next({ name: 'login' })
|
||||
} else if (store.getters['auth/user'].role == 'admin') {
|
||||
} else if (store.getters['auth/role'] == 'admin') {
|
||||
next({ name: 'admin.home' })
|
||||
} else {
|
||||
next()
|
||||
|
||||
@@ -5,13 +5,15 @@ import * as types from '../mutation-types'
|
||||
// state
|
||||
export const state = {
|
||||
user: null,
|
||||
token: Cookies.get('token')
|
||||
token: Cookies.get('token'),
|
||||
role: null
|
||||
}
|
||||
|
||||
// getters
|
||||
export const getters = {
|
||||
user: state => state.user,
|
||||
token: state => state.token,
|
||||
role: state => state.role,
|
||||
check: state => state.user !== null
|
||||
}
|
||||
|
||||
@@ -23,7 +25,9 @@ export const mutations = {
|
||||
},
|
||||
|
||||
[types.FETCH_USER_SUCCESS] (state, { user }) {
|
||||
console.log(user)
|
||||
state.user = user
|
||||
state.role = user.role
|
||||
},
|
||||
|
||||
[types.FETCH_USER_FAILURE] (state) {
|
||||
@@ -33,6 +37,7 @@ export const mutations = {
|
||||
|
||||
[types.LOGOUT] (state) {
|
||||
state.user = null
|
||||
state.role = null
|
||||
state.token = null
|
||||
|
||||
Cookies.remove('token')
|
||||
|
||||
Reference in New Issue
Block a user