-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: change localstorage in constructor to synchronous request #36
Comments
@ykdojo @thorwebdev Any thoughts on this one? I guess we might be able to detect if the storage is |
I wonder if we can make two versions of _recoverSession() (async and sync), and decide which one to use by detecting whether or not the user's using React Native here: |
I like that idea @ykdojo Not sure how we can detect if local storage is async, but i guess can run the |
SupabaseClient uses internal auth.session and auth user to set authorization headers. But they are always set to null for initial calls. While waiting for this issue to be fixed, is there another way to set authorization/bearer headers? |
To be clear, on web So not entirely sure if there's a different issue at play here. |
Also, you will need the |
I'm not an experienced JS developer. Maybe you could be right in this case. It depends on the implementation. But this is how concurrency in computer systems in general works. Edit: Learned something new today <3
|
Hi, any news ? It's really an annoying bug, can't just check if something is written in LocalStorage since it might be outdated To be clear I'm using a Vue 3 SPA client side rendered and the first call still returns |
I coded up a solution here, with this caveat: https://github.com/supabase/gotrue-js/pull/68/files#r598291376 I don't know if I would call it a bug - in many cases we need to verify that the token is still valid, and if it's not valid we need to make a request to the server to refresh the token. This requires an API call, so there is no way we can synchronously return a new session from the constructor. This change will solve any problems that people are having with refreshing the page however. If there is a valid session (set up within the last 60 mins) it will be immediately returned from the constructor |
Feature request
Is your feature request related to a problem? Please describe.
https://github.com/supabase/gotrue-js/blob/cccc4f49f6de8067b68c6892fa471a5dd544d4cb/src/GoTrueClient.ts#L57
Since the call to
_recoverSession
is async, it means thatcurrentSession
andcurrentUser
isn't populated by the constructor, and that clients need to wait for the stateChangeEmmitter to fire.This is causing a lot of problems [1] [2]
Describe the solution you'd like
LocalStorage is synchronous, so we can remove the await. However we will need a way to handle it for ReactNative.
Is there a way we can handle it for both situations?
Additional context
Side note - I have seen some people complaining that globalThis is undefined. This is also related to storage. Should this also be updated to something that works everywhere?
https://github.com/supabase/gotrue-js/blob/cccc4f49f6de8067b68c6892fa471a5dd544d4cb/src/GoTrueClient.ts#L10
The text was updated successfully, but these errors were encountered: