Skip to content

Commit

Permalink
The SvelteKit SSR example of +layout.svelte with invalidation call
Browse files Browse the repository at this point in the history
See my issue supabase/auth-helpers#742

The SvelteKit documentation may be improved mainly by adding  src/routes/+layout.svelte example with invalidation call.
  • Loading branch information
kvetoslavnovak authored Feb 12, 2024
1 parent b4a1945 commit 085eb1a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion apps/docs/content/guides/auth/server-side/creating-a-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export const handle: Handle = async ({ event, resolve }) => {
/**
* Note: You have to add the `path` variable to the
* set and remove method due to sveltekit's cookie API
* requiring this to be set, setting the path to an empty string
* requiring this to be set, setting the path to '/'
* will replicate previous/standard behaviour (https://kit.svelte.dev/docs/types#public-types-cookies)
*/
set: (key, value, options) => {
Expand Down Expand Up @@ -552,6 +552,29 @@ export const load: LayoutServerLoad = async ({ locals: { getSession } }) => {

</TabPanel>

<TabPanel id="layout-svelte" label="Root Layout Page">

```svelte +layout.svelte
// src/routes/+layout.svelte
<script>
import { invalidate } from '$app/navigation';
import { onMount } from 'svelte';
export let data;
$: ({ supabase } = data);
onMount(async () => {
supabase.auth.onAuthStateChange((event, _session) => {
invalidate('supabase:auth');
});
return () => subscription.unsubscribe();
});
</script>
```

</TabPanel>

<TabPanel id="page-component" label="Page Component">

```svelte +page.svelte
Expand Down

0 comments on commit 085eb1a

Please sign in to comment.