chore: cleaner way to implement redirect if role permission denied
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
import type { GroupPerson } from '$lib/utils/types';
|
||||
|
||||
export let allowedRoles: number[] = [];
|
||||
export let onDenied = () => {};
|
||||
|
||||
let userRole: number = 0;
|
||||
|
||||
@@ -11,6 +12,10 @@
|
||||
const user: GroupPerson = $group.people.find((person) => person.profile_id === $profile.id)!;
|
||||
|
||||
userRole = user ? user.role_id : userRole;
|
||||
|
||||
if ($group.people.length && !allowedRoles.includes(userRole)) {
|
||||
onDenied();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user