Need to reload to use Supabase auth

Whenever I sign in on Supabase (I've tested Firefox and Brave), it brings me back to the home page as it should but I'm not authenticated. Although, after I reload the page, I am authenticated and everything works as intended. How would I go about solving this bug?
22 Replies
harsh singh
harsh singhOP4y ago
and I have even tried reloading after I run my function. No luck at all. Please ping me if you end up responding, solving this bug is pretty critical to my application :ferrisSob:
garyaustin
garyaustin4y ago
@harsh singh Normally you need to monitor .onAuthStateChange() for a SIGNED_ID event and not use the session until after that. V2 I believe getSession() will actually wait for things to resolve.
harsh singh
harsh singhOP4y ago
Wait, will I need to use the authentication helpers for this? Because that's not an option for me since my backend is in Rust and pretty much completely separate from everything
garyaustin
garyaustin4y ago
How are you sending the jwt to your backend right now?
harsh singh
harsh singhOP4y ago
I'm using social auth I'm using the Supabase library to login from the frontend My backend doesn't have much to do with the authentication at all
garyaustin
garyaustin4y ago
I don't know what your question is then about auth helpers.
harsh singh
harsh singhOP4y ago
Oh no, I thought the getSession was only for auth helpers?
garyaustin
garyaustin4y ago
Auth-helpers is only for doing server side stuff. The supabase-js will handle all auth on it's own. getSession replaces .session() in supabase-js v2.
harsh singh
harsh singhOP4y ago
Awesome! is this out yet or no?
garyaustin
garyaustin4y ago
Yes. I've ported over and all seems fine... It is still rc
harsh singh
harsh singhOP4y ago
Oh, I see
garyaustin
garyaustin4y ago
You can use it certainly on a new app. @supabase/supabase-js@v2.0.0-rc.4 is out now. You really should start using v2 for anything new. I think 3 months is maintenance support for v1.
harsh singh
harsh singhOP4y ago
I'll try that out, thanks for letting me know! and I'll tell you how it goes too Quick question @garyaustin, can getUser run on the server? :blob_think:
garyaustin
garyaustin4y ago
With a jwt parameter yes.
harsh singh
harsh singhOP4y ago
I see. What if I'm using GitHub OAuth?
garyaustin
garyaustin4y ago
The user jwt access token does not matter how you signed in.
harsh singh
harsh singhOP4y ago
Oh. Where could I get that from?
harsh singh
harsh singhOP4y ago
Also, I'm having some issues, for instance I want to get my thing working without using await:
No description
garyaustin
garyaustin4y ago
It is in the session object
harsh singh
harsh singhOP4y ago
Oh, I see.
garyaustin
garyaustin4y ago
You probably need to ask new question if more. I’m out.
harsh singh
harsh singhOP4y ago
Oh alright, thanks for your help. This issue works with the upgrade. Thanks for that tip. I'll close this in favour of #Unable to use getUser without async

Did you find this page helpful?