Hi, looks like supabase works smooth with Svelte, ...
# javascript
m
Hi, looks like supabase works smooth with Svelte, React, Vue... (SPAs) but when you want to use SSR (Sveltekit, Next, Nuxt) [i'm using sveltekit] the issue is kind of similar... to work with authentication... in the server side is not initiated the supabaseClient so you can't check if it's authenticated, neither can do SSR because you don't have the token of the user... any help? I've been reading for hours online and I don't see a nice way to go...
s
Hi, looks like supabase works smooth with Svelte, React, Vue... (SPAs) but when you want to use SSR (Sveltekit, Next, Nuxt) [i'm using sveltekit] the issue is kind of similar... to work with authentication... in the server side is not initiated the supabaseClient so you can't check if it's authenticated, neither can do SSR because you don't have the token of the user... any help? I've been reading for hours online and I don't see a nice way to go...
m
thanks I read that one, not sure how to differenciate the good from bad, but so far that one was one of the best articles
thanks
s
That's the approach I take with Sveltekit too and it works well for me
m
I tried once didn't make it work, gonna try again
thanks siletworks
s
m
I think my issue when I tried was that handle() expects now event rather than request, and I didn't know how to go from here..., maybe my sveltekit is more updated
s
Oh are you on the latest SvelteKit? I know they changed how handle works. I will update the project over the weekend to cater for the new changes in SvelteKit
The changes that were made was to make working with handlers easier
m
the debugger makes so easy to do those changes, it says: this method was replaced by this, then you change and voila!
s
Ok let me do a quick run now and see if I can make the update to this project
m
let me know if you make it work, I'm stuck here
i don't think it has an easy solution, if I put on line 168 event.request then that's the error because inside that function tries to access that object.body and if I put: event then the error is that in that function can't access to event.method because it should be event.requesst.method
s
Ok I've progressed pass that issue, but another one came up right after
m
really?
I'm still in that one
how did you solve it?
it looks like setAuthCookie() is expecting a request in a format that I don't know what it is but I tried sending it... toExpressRequest(event.request)
didn't work either
you have no idea how many hours I've spent on this... xD
i'm checking for your response every 10 minutes, no pressure xD
s
haha yeah it requires a certain format, I'm currently creating that format before sending it over to setAuthCookie
Update the code inside of your if block to
Copy code
js
const reqBody = await request.json()
supabase.auth.api.setAuthCookie(
  { ...request, body: reqBody, headers: { host: request.headers.get('host') } },
  toExpressResponse(response)
)
Your next error should do with the response, but we can resolve that after
m
I was super close to what you did... and I made that far to see that the next error was response, and then I said right now... I can't ... and I saw your message
that gave me confidence we can solve this 🙂
are we the only two people with this issue in the entire world?
s
I don't think we are, my new issue is the cookie is not being set at all
for the response just delete the
response = toSvelteKitResponse(response)
and that resolves it
m
we are the same place then
i did it
s
But cookies aren't being set, so I need to debug that but I need to get back to work
m
ok, thanks for everything @User , I thought the cookie was set if you responded but looks like it has to be after that line
s
I think something else might be missing as to why the cookie isn't being set
as in
setAuthCookie
is missing something in the request we are sending to it
m
maybe doing this...->
auth.api.setAuthCookie( { ...expressStyleRequest,
?
s
No the expressStyleRequest doesn't contain all the properties required
It doesn't have the correct
body
in it as SvelteKit is now using the native Request body and you need to do
await request.json()
in order to get the json version of that body else its just a readstream
m
nah, I can't figure out, when you have time have a look to this article and tell me what are the benefits of doing the cookie as we are trying now Vs this article, maybe that's the solution?
s
I think you forgot to link the article
m
sorry
too many hours with the same issue
my brain
what do you think is best, the way we are trying or this one?
s
In essence this is what we are currently trying to do
m
I make it work with that article, so I will go that way for now as there is not a benefit on doing it in the way we were trying
Thanks
s
What happens when you refresh the page?
Ok finally fixed it, I will push an update to my project and try to simplify the code to make it easier with the latest SvelteKit
My project here has all the changes to get this working with the latest SvelteKit again https://github.com/silentworks/waiting-list