The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix infinite redirect bug in SvelteKit docs
Andrew Smitha22e151d8684
diff --git a/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx b/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdxindex 99449d191e0..4873b795180 100644--- a/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx+++ b/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx@@ -142,13 +142,15 @@ We need to create an event listener in the root `+layout.svelte` file in order cexport let data: LayoutData;- $: ({ supabase } = data);+ $: ({ supabase, session } = data);onMount(() => {const {data: { subscription },- } = supabase.auth.onAuthStateChange(() => {- invalidate('supabase:auth');+ } = supabase.auth.onAuthStateChange((event, _session) => {+ if (_session?.expires_at !== session?.expires_at) {+ invalidate('supabase:auth')+ }});return () => subscription.unsubscribe();@@ -185,26 +187,6 @@ declare global {}```-### Basic Setup--You can now determine if a user is authenticated on the client-side by checking that the `session` object in `$page.data` is defined.--```html-<!-- src/lib/components/Header.svelte -->-<script lang="ts">- import type { Session } from '@supabase/supabase-js';-- export let session: Session | null;-</script>--{#if !session}- <h1>I am not logged in</h1>-{:else}- <h1>Welcome {session.user.email}</h1>- <p>I am logged in!</p>-{/if}-```-## Client-side data fetching with RLSFor [row level security](https://supabase.com/docs/guides/auth/row-level-security) to work properly when fetching data client-side, you need to use `supabaseClient` from `PageData` and only run your query once the session is defined client-side:@@ -562,13 +544,15 @@ export const load: LayoutLoad = async ({ fetch, data, depends }) => {export let data: LayoutData;- $: ({ supabase } = data);+ $: ({ supabase, session } = data);onMount(() => {const {data: { subscription },- } = supabase.auth.onAuthStateChange(() => {- invalidate('supabase:auth');+ } = supabase.auth.onAuthStateChange((event, _session) => {+ if (_session?.expires_at !== session?.expires_at) {+ invalidate('supabase:auth')+ }});return () => subscription.unsubscribe();diff --git a/apps/docs/pages/guides/getting-started/tutorials/with-sveltekit.mdx b/apps/docs/pages/guides/getting-started/tutorials/with-sveltekit.mdxindex 22b154c836c..c67ccea9008 100644--- a/apps/docs/pages/guides/getting-started/tutorials/with-sveltekit.mdx+++ b/apps/docs/pages/guides/getting-started/tutorials/with-sveltekit.mdx@@ -179,11 +179,13 @@ Update your `src/routes/+layout.svelte`:export let data: LayoutData- $: ({ supabase } = data)+ $: ({ supabase, session } = data)onMount(() => {- const { data } = supabase.auth.onAuthStateChange(() => {- invalidate('supabase:auth')+ const { data } = supabase.auth.onAuthStateChange((event, _session) => {+ if (_session?.expires_at !== session?.expires_at) {+ invalidate('supabase:auth')+ }})return () => data.subscription.unsubscribe()