Figured out auth & middlewares

This commit is contained in:
Julien Nahum
2023-12-16 19:21:03 +01:00
parent be891b0615
commit 7c2db2052a
38 changed files with 4862 additions and 1189 deletions

View File

@@ -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()
}

View File

@@ -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()
}