• Authenticated Supabase client

    Returns a new authenticated Supabase client.

    When running in the browser it will create a single instance that is returned for subsequent runs.

    Example:

    import { invalidate } from '$app/navigation';
    import { PUBLIC_SUPABASE_ANON_KEY, PUBLIC_SUPABASE_URL } from '$env/static/public';
    import { createSupabaseLoadClient } from '@supabase/auth-helpers-sveltekit';
    import type { LayoutLoad } from './$types';

    export const load: LayoutLoad = async ({ fetch, data, depends }) => {
    depends('supabase:auth');

    const supabase = createSupabaseLoadClient({
    supabaseUrl: PUBLIC_SUPABASE_URL,
    supabaseKey: PUBLIC_SUPABASE_ANON_KEY,
    event: { fetch },
    serverSession: data.session,
    onAuthStateChange() {
    invalidate('supabase:auth');
    }
    });

    const {
    data: { session }
    } = await supabase.auth.getSession();

    return { supabase, session };
    };

    Type Parameters

    • Database = any

    • SchemaName extends string = "public" extends keyof Database
          ? "public"
          : string & keyof Database

    • Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
          ? any[any]
          : any

    Parameters

    • __namedParameters: {
          cookieOptions?: CookieOptionsWithName;
          event: Pick<LoadEvent<Partial<Record<string, string>>, null | Record<string, any>, Record<string, any>, null | string>, "fetch">;
          options?: SupabaseClientOptionsWithoutAuth<SchemaName>;
          serverSession: null | Session;
          supabaseKey: string;
          supabaseUrl: string;
      }
      • Optional cookieOptions?: CookieOptionsWithName
      • event: Pick<LoadEvent<Partial<Record<string, string>>, null | Record<string, any>, Record<string, any>, null | string>, "fetch">
      • Optional options?: SupabaseClientOptionsWithoutAuth<SchemaName>
      • serverSession: null | Session

        The initial session from the server.

      • supabaseKey: string

        The supabase key. Make sure you always use the ANON_KEY.

      • supabaseUrl: string

    Returns SupabaseClient<Database, SchemaName, Schema>