Skip to content
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

refactor: Combine the storage interface for storage and pkce in gotrue_client #1087

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Vinzent03
Copy link
Collaborator

@Vinzent03 Vinzent03 commented Nov 21, 2024

What kind of change does this PR introduce?

refactor

What is the current behavior?

The session gets stored by the supabase_flutter package by listening to auth events. The session is stored in a different place than the pkce token.

What is the new behavior?

The gotrue package manages the session storage itself (like in supabase-js) and uses the same interface as the pkce token.

Reasons for this pr:

  • Have a more similar approach to saving the session like in supabase-js
  • Make it less confusing for the user to have to provide two different storage interfaces to customize the storage of the session and the pkce token
  • Provide a built-in interface to persist the session if not using supabase_flutter
  • The auth client has now the persistSession field, which is now used to explicitly turn on the session broadcasting. close Version 2.7.0 prevents reading data on web under certain conditions #1085

I deprecated both localStorage (used for session storage by supabase_flutter) and pkceAsyncStorage (used by supabase to store the pkce token) and replace them with a unified storage interface asyncStorage, which uses the GotrueAsyncStorage class, which was previsouly used for pkce only. To support existing configuration I created a new class, which combines both deprecated interfaces into one and decides by the suffix of the storage key to use the session storage or pkce storage.

Additionally, I noticed that many document comments were outdated, because of the 'new' options classes for each package, so I updated them.

Additional context

@Vinzent03 Vinzent03 force-pushed the refactor/auth-storage branch from c006dd1 to 0ae2b71 Compare November 21, 2024 20:50
@Vinzent03 Vinzent03 changed the title refactor: store session and pkce in the same storage in gotrue_client refactor: Combine the storage interface for storage and pkce in gotrue_client Nov 21, 2024
@Vinzent03 Vinzent03 marked this pull request as ready for review November 23, 2024 16:00
@Vinzent03 Vinzent03 requested a review from dshukertjr November 23, 2024 16:00
@dshukertjr
Copy link
Member

Thanks for this PR, but honestly, I am not a huge fan of these refactorings. I feel like the library is deviating more and more from supabase-js, which makes it hard to maintain. Unless there is something broken, I'd say we keep it the way it is, and maybe we can revisit it when a major version release comes.

@Vinzent03
Copy link
Collaborator Author

I'm quite confused, because the whole goal of this pr is to align with supabase-js .

  • This now uses a single storage interface like supabase-js -> session and pkce are no longer handled separately like it's done in supabase-js
  • This now uses the same storage interface like supabase-js
  • The session is stored by the auth client itself like in auth-js instead of having to listen to the onAuthStateChange stream in supabase_flutter.
  • The session is only broadcasted if the session is persisted, just like in auth-js

So this pr makes it easier to maintain the similarity to the js sdk.
Example:
Beforehand it was not possible to disable the session broadcasting like in auth-js, which I already mentioned in that pr, because the sdk were deviated. But with these changes it's implemented like in supabase-js

@dshukertjr
Copy link
Member

It's a refactoring that doesn't really solve any issues that users are asking for. We can probably wait for a major version bump for changes like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 2.7.0 prevents reading data on web under certain conditions
2 participants