17 lines
450 B
JavaScript
17 lines
450 B
JavaScript
export default async function ({ $auth, redirect, route }) {
|
|
try {
|
|
if (route.name === 'admin') {
|
|
return true
|
|
} else {
|
|
let hasPermission = false
|
|
for await (const permission of $auth.user.permissions) {
|
|
if ((await route.name.includes(permission)) && permission !== '') hasPermission = true
|
|
}
|
|
if (hasPermission) return true
|
|
else redirect('/admin')
|
|
}
|
|
} catch (e) {
|
|
redirect('/admin')
|
|
}
|
|
}
|