https://supabase.com/ logo
#javascript
Title
# javascript
b

beru

01/28/2022, 10:25 AM
does anyone know why
auth.user()
doesn't work in the
load()
function in sveltekit? it always returns
null
, even though it works fine in the regular script tags. in the load function, i'm trying to query from a table with a rls policy
auth.role() = 'authenticated
, but it keeps failing. changing the check with
auth.role() = 'anon'
works for some reason. i'm guessing this is related to the
auth.user()
returning
null
.
c

chipilov

01/28/2022, 10:41 AM
Yep, this is most likely the reason. I have an explanation about why I think this happens here: https://github.com/supabase/gotrue-js/issues/143#issuecomment-970288835
The workaround is to introduce 3 states for your user: (1) unauthenticated (2) pending authentication (3) authenticated
v

VincentThomas

01/28/2022, 10:42 AM
I don't know sveltekit very well, but the auth.user() function works only on the client.
Because its stored in localStorage
c

chipilov

01/28/2022, 10:43 AM
aaaa, good point @User - the explanation I linked is actually about the client
v

VincentThomas

01/28/2022, 10:44 AM
is the load() function on the server?
b

beru

01/28/2022, 10:46 AM
it runs on both the server & the client
v

VincentThomas

01/28/2022, 10:47 AM
I guess its not made for fetching data then? That would be inefficient! What do you use it for?
b

beru

01/28/2022, 10:49 AM
i'm using it to get the data from supabase before the component loads
v

VincentThomas

01/28/2022, 10:49 AM
Would that not load it twice?
b

beru

01/28/2022, 10:49 AM
i'm not sure myself
v

VincentThomas

01/28/2022, 10:49 AM
Or is it one function that does not stop loading?
b

beru

01/28/2022, 10:50 AM
it's like getServerSideProps from nextjs
v

VincentThomas

01/28/2022, 10:50 AM
But that only runs on the server?
b

beru

01/28/2022, 10:51 AM
in sveltekit it runs on the client too. i got this from the docs, but not sure as to how it actually works
v

VincentThomas

01/28/2022, 10:52 AM
But then you just load the resources from apis or whatever twice, don't you?
b

beru

01/28/2022, 10:52 AM
yes probablty
v

VincentThomas

01/28/2022, 10:53 AM
Thats wierd.