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>
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import { globalStore } from '$lib/utils/store/app';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export function redirectToLesson(settings, courseId) {
|
||||
const globalStoreVal = get(globalStore);
|
||||
|
||||
if (!settings && globalStoreVal.isOrgSite) {
|
||||
goto(`${courseId}/lessons?next=true`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user