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

feat: Add listSessions and revokeSession methods to GoTrueClient #1042

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nicokempe
Copy link

Warning

The required endpoints in the supabase/auth API have not yet been added, this is currently just a concept related to https://github.com/orgs/supabase/discussions/34340.

What kind of change does this PR introduce?

This PR adds a new feature to the Supabase Auth JavaScript SDK. It introduces two new public methods — listSessions() and revokeSession(sessionId: string) — to the GoTrueClient class. These methods enhance session management by allowing developers to list all active sessions for the current user and to revoke a specific session.

What is the current behavior?

Currently, the SDK provides methods for sign-in, sign-out, and token refresh, but it does not expose any functionality for listing or revoking individual user sessions. Developers can only sign out of the current session or all sessions without granular control.

What is the new behavior?

  • listSessions(): Retrieves all active sessions for the current user via a GET request to the /sessions endpoint. It returns a sessions array or an error if the operation fails.
  • revokeSession(sessionId: string): Revokes a specific session by its session ID through a DELETE request to /sessions/{sessionId}. If the revoked session matches the current session, the method also clears it from local storage.

Both methods follow the existing initialization, locking, and error handling patterns in GoTrueClient, ensuring consistency and reliability with the rest of the SDK.

Additional context

This enhancement addresses a common feature request for granular session management similar to what is available in other major platforms. Although this PR does not include new tests, it aligns with the SDK's established code style and behavior. Future iterations may add dedicated tests for these new methods.

Context

…lient

- Introduces two new public methods in GoTrueClient to enhance session management.
- listSessions retrieves all active sessions for the current user via a GET request to the /sessions endpoint.
- revokeSession revokes a specific session via a DELETE request to /sessions/{sessionId}. If the revoked session matches the current session, it removes the session from local storage.
- Both methods follow the existing initialization, locking, and session handling patterns.
- JSDoc comments have been added for documentation and clarity.

More context: https://github.com/orgs/supabase/discussions/34340
@nicokempe nicokempe changed the title [Draft] Add listSessions and revokeSession methods to GoTrueClient feat: Add listSessions and revokeSession methods to GoTrueClient Mar 22, 2025
@j4w8n
Copy link
Contributor

j4w8n commented Mar 22, 2025

I haven't looked at the details, but I'd like to +1 this. Been on my "list" for a while; good to see someone lay down some code.

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.

2 participants