chore: cleaner way to implement redirect if role permission denied

This commit is contained in:
Rotimi Best
2024-05-19 18:55:28 +01:00
parent f21bc80dba
commit b6fa251bcd
5 changed files with 51 additions and 26 deletions
@@ -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>
-11
View File
@@ -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`);
}
}