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

Save the session in the AuthClient #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

martin-g
Copy link

@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 floris-xlx/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 <[email protected]>
@martin-g
Copy link
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!

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