onAuthStateChange never firing.

Hi,

I'm a little confused here. According the docs onAuthStateChange() fires everytime an auth event happens. I'm using the Auth Helpers sveltekit guide and set everything up and is working great.

I am setting up a password reset flow, and I am trying to capture the PASSWORD_RECOVERY event. Problem is, the onAuthStateChange event is never firing.

I set it up exactly as article describes (https://supabase.com/docs/guides/auth/auth-helpers/sveltekit#synchronizing-the-page-store)

Even if I try to do a basic console log from the root layout when signing in and out, no event ever seems to fire.

<script>
  import { supabase } from "$lib/db";
  import { invalidate } from "$app/navigation";
  import { onMount } from "svelte";
  import "../app.css";

import {page} from '$app/stores';

  export let data;

  onMount(() => {
    //synchronize supabase session to page store
    const {
      data: { subscription },
    } = supabase.auth.onAuthStateChange((event, session) => {
      console.log(event, "State changed")
      invalidate("supabase:auth");
    });

    return () => {
      subscription.unsubscribe();
    };
  });

  $: console.log($page)
</script>

<svelte:head>
  <link rel="stylesheet" href="https://rsms.me/inter/inter.css">
</svelte:head>

<slot />
Supabase Documentation
Convenience helpers for implementing user authentication in SvelteKit.
Was this page helpful?