Skip to content

Function: setRbacContext() ​

ts
function setRbacContext<T, G>(snapshot, options?): SvelteRbac<T, G>;

Defined in: packages/sveltekit/src/context.svelte.ts:101

Puts the current user's roles & permissions in the component context, for getRbacContext(), <Can> and <HasRole> below it. Call it in the root +layout.svelte, with a getter so it follows the layout data:

svelte
<script lang="ts">
  import { setRbacContext } from '@anievo-id/rbac-evolution-sveltekit'
  let { data, children } = $props()
  setRbacContext(() => data.rbac, { superAdminRoles: ['super-admin'] })
</script>

Must be called during component initialisation (like Svelte's setContext).

Type Parameters ​

Type ParameterDefault type
T extends RbacTypeConfig | Rbac<RbacTypeConfig>DefaultRbacTypes
G extends stringDefaultGuardName<TypesOf<T>>

Parameters ​

ParameterType
snapshotRbacSnapshotSource
options?RbacCheckerOptions

Returns ​

SvelteRbac<T, G>

Released under the MIT License. Inspired by spatie/laravel-permission.