Figured out auth & middlewares
This commit is contained in:
19
resources/js/middleware/notion-connection.js
vendored
19
resources/js/middleware/notion-connection.js
vendored
@@ -1,19 +0,0 @@
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
|
||||
export default async (to, from, next) => {
|
||||
const authStore = useAuthStore()
|
||||
if (authStore.check && authStore.user?.workspaces_count === 0) {
|
||||
if ([
|
||||
'forms.create',
|
||||
'forms.show',
|
||||
'forms.edit',
|
||||
'home'
|
||||
].includes(to.name)
|
||||
) {
|
||||
next({ name: 'onboarding' })
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
next()
|
||||
}
|
||||
21
resources/js/middleware/role.js
vendored
21
resources/js/middleware/role.js
vendored
@@ -1,21 +0,0 @@
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
|
||||
/**
|
||||
* This is middleware to check the current user role.
|
||||
*
|
||||
* middleware: 'role:admin,manager',
|
||||
*/
|
||||
|
||||
export default (to, from, next, roles) => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// Split roles into an array
|
||||
roles = roles.split(',')
|
||||
|
||||
// Check if the user has one of the required roles...
|
||||
if (!roles.includes(authStore.user?.role)) {
|
||||
next('/unauthorized')
|
||||
}
|
||||
|
||||
next()
|
||||
}
|
||||
Reference in New Issue
Block a user