Closed angezanetti closed 1 year ago
What version of the auth helper are your using? I can't replicate this issue in the latest version.
My guess is that you forgot to import $lib/db
inside both hooks files hooks.client.js
and hooks.server.js
.
We probably want to throw an error with a better error message if we call getConfig
internally but createClient
wasnt called before.
Edit:
Sorry, should have completely read through the issue first
But i´m not able to reproduce the issue aswell.
The only thing i noticed is that i had to restart the dev server when i created hooks.client.js
but that´s a sveltekit issue.
Could you share a reproduction?
I get this issue when trying to follow this in StackBlitz. Not seen it when running the tutorial on my local machine.
So not sure if this is a StackBlitz
See: https://stackblitz.com/edit/sveltejs-kit-template-default-jrbksc?file=package.json
You will need to add your own .env file
Take a look at this section: https://supabase.com/docs/guides/auth/auth-helpers/sveltekit#set-up-the-supabase-client
You need to import lib/db
in both hooks files to actually load the client
Edit:
Oh, you created both hooks files. But they need to be located in /src
Thanks @david-plugge you spotted my issue. I wonder if original poster also made the same mistake I did, having hooks files outside src folder.
Thanks a lot too, my issue was having the hook files inside of routes instead of the /src folder, this really helped a lot
Hi 👋🏻 Having the same issue right now, here is my reproduction repository: https://github.com/Olyno/supabase-svelte-helper-auth-repro
This issue happens only on the http://localhost:3000/auh page for some reasons.
Hi @Olyno, I think you forgot to push some changes, the repo shows a plain sveltekit app without supabase installed
Oh nice catch, i pushed it on the wrong branch 😅 fixed!
Alright, it seems like you are missing a hooks.client.ts
file with the import from $lib/db
. The import is necessary because the helpers must be initialized before any load functions run
Indeed, the hooks.client.ts
file was missing, it solves the issue, thank you! May i ask why do we need 2 kind of hooks to use the helper?
I had the same error, and followed the suggestions from this issue and issue #310 and nothing was helping. I ended up wrapping await getSupabase(event)
from +layout.ts
in a try catch block and that "fixed" it. It seems that on initial load of the vite sveltekit server getLoadSupabaseClient
is being called before setConfig
.
Code is outdated and no longer used.
Bug report
Describe the bug
I followed the @supabase/auth-helpers-sveltekit guide on how to integrate supabase-auth helpers with sveltekit.
It works, but when I stop my server and start it again with
npm run dev
I got the error:I checked the issue #310, but I import the right package in
$lib/db
and I do have thehooks.client.js
and thehooks.server.js
witht theimport $lib/db
To Reproduce
Follow the guide, and restart your local server
Expected behavior
It should handle the sessions
Screenshots
System information