Skip to content

Commit 1451bdf

Browse files
refactor: replace laravel-vuejs-permissions with vue-middleware
1 parent 37418c3 commit 1451bdf

File tree

10 files changed

+110
-224
lines changed

10 files changed

+110
-224
lines changed

package-lock.json

Lines changed: 86 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"vue": "^3.2.47",
3535
"vue-chart-3": "^3.1.8",
3636
"vue-i18n": "^9.2.2",
37+
"vue-middleware": "^1.0.0-alpha.5",
3738
"vue-router": "^4.1.6",
3839
"vuetify": "^3.4.9",
3940
"wavesurfer.js": "^7.1.2",

src/main.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ app.config.globalProperties.$slice = (string, length = 25) => {
1616
return string.length >= length ? string.slice(0, length) + '...' : string
1717
}
1818

19+
app.use(pinia)
20+
app.use(router)
21+
1922
// Register plugins
2023
plugins(app)
2124

22-
// Use Vue plugins
23-
app.use(pinia).use(router)
24-
25-
// Run before each method of the router
26-
router.watch(app)
27-
2825
// Mount!
2926
app.mount('#app')

src/middleware/dashboard.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { useAuthStore } from '@/stores/auth'
22

3-
export default ({ router, next, guest }) => {
3+
export default ({ redirect, guard }) => {
44
const authStore = useAuthStore()
55

66
// This is an authenticated route but the user
77
// is not logged in so redirect to the login page.
8-
if (!guest && !authStore.isLoggedIn) {
9-
return router.push('/login')
8+
if (guard !== 'guest' && !authStore.isLoggedIn) {
9+
return redirect('/login')
1010
}
1111

1212
// This is a guest route, and the user is authorized
1313
// let's redirect him/her to the dashboard home page.
14-
if (guest && authStore.isLoggedIn) {
15-
return router.push('/dashboard')
14+
if (guard === 'guest' && authStore.isLoggedIn) {
15+
return redirect('/dashboard')
1616
}
17-
18-
next()
1917
}

src/pages/auth/login.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ import AppAuthHeading from '@/components/auth/Heading.vue'
8787
const appStore = useAppStore()
8888
const authStore = useAuthStore()
8989
const form = useForm({
90-
90+
email: 'admin@starter',
9191
password: 'password',
9292
})
9393

src/plugins/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import './axios'
22
import './vform'
33
import './laravel-echo'
4-
import './lodash'
54

65
// Callable plugins
6+
import { useVueMiddleware } from './vue-middleware'
77
import { useVuetify } from './vuetify'
88
import { useGlobalComponents } from './global-components'
9-
import { useLaravelPermissions } from './laravel-permissions'
109

1110
// Call the callalble plugins that needs to the app instance
1211
// for registeration purposes, since we're using Vue v3
1312
// we need the app instance to register components and plugins etc..
1413
export const plugins = (app) => {
14+
useVueMiddleware(app)
1515
useVuetify(app)
16-
useLaravelPermissions(app)
1716
useGlobalComponents(app)
1817
}

src/plugins/laravel-permissions.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/plugins/vue-middleware.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import vueMiddleware, { LaravelPermissionsDriver } from 'vue-middleware'
2+
import middleware from '@/middleware'
3+
4+
export const useVueMiddleware = (app) => {
5+
app.use(vueMiddleware, {
6+
middleware,
7+
permissions: {
8+
driver: LaravelPermissionsDriver,
9+
},
10+
})
11+
}

0 commit comments

Comments
 (0)