mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-07 21:29:06 +00:00
Initial commit
This commit is contained in:
22
lib/components/permission-guard.svelte
Normal file
22
lib/components/permission-guard.svelte
Normal file
@@ -0,0 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { authStore, canAccess } from '$lib/stores/auth';
|
||||
import type { Snippet } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
resource: string;
|
||||
action: string;
|
||||
children: Snippet;
|
||||
fallback?: Snippet;
|
||||
}
|
||||
|
||||
let { resource, action, children, fallback }: Props = $props();
|
||||
|
||||
// Check if user can access the resource/action
|
||||
const hasAccess = $derived($canAccess(resource, action));
|
||||
</script>
|
||||
|
||||
{#if hasAccess}
|
||||
{@render children()}
|
||||
{:else if fallback}
|
||||
{@render fallback()}
|
||||
{/if}
|
||||
Reference in New Issue
Block a user