Auth

With Routify, you don't need any router included functions to authenticate users and protect your app.

Since everything in Routify is scoped, protecting a layout automatically protects all nested components recursively.

Authentication guards

Users should generally be authenticated in the root layout.

<!-- src/pages/_layout.svelte --> <script> import { authenticate } from 'my-auth-service' </script> <!-- Wait with rendering the app till the user/guest is verified. This prevents small UI glitches and premature authorization checks. --> {#await authenticate()} {:then} <slot /> {/await}
<!-- src/pages/_layout.svelte -->
<script>
  import { authenticate } from 'my-auth-service'
</script>

<!-- Wait with rendering the app till the user/guest is verified.
This prevents small UI glitches and premature authorization checks. -->
{#await authenticate()}
{:then}
  <slot />
{/await}

Authorization Guards

Guards should be implemented in the component or module which they protect.

<!-- src/pages/admin/_layout.svelte --> <script> export let scoped </script> {#if scoped.user.isAdmin} <slot /> {/if}
<!-- src/pages/admin/_layout.svelte -->
<script>
  export let scoped
</script>

{#if scoped.user.isAdmin}
  <slot />
{/if}

Realtime guards

For realtime guards, simply replace {#await <promise>} with {#if <reactive condition>}


Writing good documentation that is up-to-date is difficult. If you notice a mistake, help us out.