Skip to content

Save the session in the AuthClient#33

Closed
martin-g wants to merge 1 commit into
supabase-community:mainfrom
martin-g:save-session-in-the-client
Closed

Save the session in the AuthClient#33
martin-g wants to merge 1 commit into
supabase-community:mainfrom
martin-g:save-session-in-the-client

Conversation

@martin-g
Copy link
Copy Markdown

@martin-g martin-g commented Mar 24, 2025

What kind of change does this PR introduce?

New feature (idea for improvement):
The Session returned by the login_*** methods is stored in the AuthClient itself.
This way the AuthClient could use the correct access_token in get_user(), get_settings(), etc. without requiring the developer to provide the access token as a method parameter. Same for the refresh_token in refresh_session() method.

What is the current behavior?

The Session is returned from the login_***() methods and it is responsibility of the user application to pass the correct token where needed.

What is the new behavior?

The Session is still returned by the login_**() methods and the user application may use it if needed.
But the AuthClient itself also keeps a handle to the last authenticated session and use its tokens appropriately where needed.

Additional context

My idea is inspired by xylex-group/supabase_rs#42
There I want to authenticate the user via supabase.auth().login_***() and start doing supabase.insert()/update()/select()/delete(). By keeping a reference to the Session the insert/update/... operations could use the correct bearer depending on whether the user is authenticated or not:
https://github.com/floris-xlx/supabase_rs/pull/42/files#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759R432-R437

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
@martin-g
Copy link
Copy Markdown
Author

I didn't do the changes in get_user() and refresh_session() before I get your feedback.
Making these changes will be API breaks!

@martin-g martin-g closed this by deleting the head repository Jul 28, 2025
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.

1 participant