Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions resources/js/middleware/admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import store from '~/store'
import Cookies from 'js-cookie'

export default (to, from, next) => {
if (!store.getters['auth/check']) {
Cookies.set('intended_url', to.path)

next({ name: 'login' })
return
}
if (store.getters['auth/user'].role !== 'admin') {
next({ name: 'home' })
} else {
Expand Down
7 changes: 7 additions & 0 deletions resources/js/middleware/role.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import store from '~/store'
import Cookies from 'js-cookie'

/**
* This is middleware to check the current user role.
Expand All @@ -7,6 +8,12 @@ import store from '~/store'
*/

export default (to, from, next, roles) => {
if (!store.getters['auth/check']) {
Cookies.set('intended_url', to.path)

next({ name: 'login' })
return
}
// Grab the user
const user = store.getters['auth/user']

Expand Down