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

fix!(gotrue): change the default signOut scope to local from global #730

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gotrue_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ jobs:
time: '5s'

- name: Run tests
run: dart test
run: dart test --concurrency=1
19 changes: 11 additions & 8 deletions packages/gotrue/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ enum OtpChannel {
whatsapp,
}

///Determines which sessions should be logged out.
///
///[global] means all sessions by this account will be signed out.
///
///[local] means only this session will be signed out.
///
///[others] means all other sessions except the current one will be signed out. When using others, there is no [AuthChangeEvent.signedOut] event fired on the current session!
enum SignOutScope { global, local, others }
/// Determines which sessions should be logged out.
enum SignOutScope {
/// All sessions by this account will be signed out.
global,

/// Only this session will be signed out.
local,

/// All other sessions except the current one will be signed out. When using others, there is no [AuthChangeEvent.signedOut] event fired on the current session!
others,
}
Comment on lines +68 to +78
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanMossa
Good point. Currently it's hard for the developers to understand what the scope parameter does. I have updated the comment docs like this to improve the situation.

If I am signed in on my app from a desktop and my smart phone and I call signOut(SignOutScope.global) on my phone, I will also be signed out from the desktop.

With local, I would only be signed out from the phone, and the desktop session will remain active. I think local is the behavior that typically developers would expect.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Yeah local definitely makes more sense then.

But I thought we use JWT tokens, so how would the Supabase goTrue server sign us out on other devices?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanMossa
I think it works by revoking the refresh token, so technically the sessions on other devices will be active until the access token expires.

4 changes: 3 additions & 1 deletion packages/gotrue/lib/src/gotrue_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,11 @@ class GoTrueClient {

/// Signs out the current user, if there is a logged in user.
///
/// [scope] dtermines which sessions should be logged out.
///
/// If using [SignOutScope.others] scope, no [AuthChangeEvent.signedOut] event is fired!
Future<void> signOut({
SignOutScope scope = SignOutScope.global,
SignOutScope scope = SignOutScope.local,
}) async {
final accessToken = currentSession?.accessToken;

Expand Down
Loading