j4w8n / supakit

A Supabase authentication helper for SvelteKit
38 stars 2 forks source link

Cannot read properties of null `session` #16

Closed philmas closed 10 months ago

philmas commented 10 months ago

Hello,

I have come across an issue.

Following your Readme.md and trying to implement:

/* src/routes/+layout.ts */
import { env } from "$env/dynamic/public";
import { createSupabaseLoadClient } from "supakit";
import type { Database } from "$lib/types/database.d";

export const load = async ({ data: { session }, depends }) => {
    depends("supabase:auth");

    const supabase = createSupabaseLoadClient<Database>(
        env.PUBLIC_SUPABASE_URL,
        env.PUBLIC_SUPABASE_ANON_KEY,
        {
            auth: {
                debug: true,
                flowType: "pkce"
            }
        }
    );

    return { supabase, session };
};

I obtain a typing error: Property 'session' does not exist on type 'null'.ts. When I run the code and try to open my page, I stumble upon TypeError: Cannot read properties of null (reading 'session') and get the 500 error.

Do you know what I might be missing?

philmas commented 10 months ago

Well, I should take the docs more at face value apparently. For anyone wondering: the issue was that I called the file +layout.ts instead of layout.ts.

philmas commented 10 months ago

Reopening, I would like some input still. I still have issues on following the documentation now.

j4w8n commented 10 months ago

yeah, how can I help?

j4w8n commented 10 months ago

Well, I should take the docs more at face value apparently. For anyone wondering: the issue was that I called the file +layout.ts instead of layout.ts.

This is strange, because SvelteKit wants you to have the + in front. Without the + it's not a SvelteKit layout file and is likely ignored.

image

philmas commented 10 months ago

Well, I should take the docs more at face value apparently. For anyone wondering: the issue was that I called the file +layout.ts instead of layout.ts.

This is strange, because SvelteKit wants you to have the + in front. Without the + it's not a SvelteKit layout file and is likely ignored.

image

It indeed seems it should be +layout.ts but for some reason I still get a session error. I have no idea why this happens to say the least. Perhaps I should start a fresh new project to try it out.

j4w8n commented 10 months ago

Were you using the supabase auth helper before? If so, and if there's still a valid browser cookie, then you'll need to delete the cookie. The way Supakit formats the auth cookie is different than the official auth helpers.

If that's not the case, then can you post some of the relevant code?

j4w8n commented 10 months ago

@philmas anything new on this?

j4w8n commented 10 months ago

Closing. No response after one week. Will re-open if needed.