Skip to content

Commit

Permalink
chore(auth): Clear browser cookies on sign-out
Browse files Browse the repository at this point in the history
  • Loading branch information
dnys1 committed Mar 9, 2024
1 parent 10549de commit c72b9ea
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/celest_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0-dev.2

- Clear browser cookies on `signOut`

## 0.3.0-dev.1

- Initial version.
2 changes: 1 addition & 1 deletion packages/celest_auth/lib/src/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ abstract interface class Auth {
Stream<AuthState> get authStateChanges;

/// Signs out the current user, if any.
void signOut();
Future<void> signOut();
}
8 changes: 6 additions & 2 deletions packages/celest_auth/lib/src/auth_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ final class AuthImpl implements Auth {
}

@override
void signOut() {
Future<void> signOut() async {
localStorage.delete('userId');
secureStorage.delete('cork');
_authStateController.add(const Unauthenticated());
try {
await protocol.signOut();
} finally {
_authStateController.add(const Unauthenticated());
}
}

final CelestBase celest;
Expand Down
4 changes: 2 additions & 2 deletions packages/celest_auth/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: celest_auth
description: The Auth runtime and client library for Celest, the Flutter cloud platform.
version: 0.3.0-dev.1
version: 0.3.0-dev.2
homepage: https://celest.dev
repository: https://github.com/celest-dev/celest/tree/main/packages/celest_auth

Expand All @@ -12,7 +12,7 @@ dependencies:
built_collection: ^5.1.1
built_value: ^8.9.1
cedar: ^0.1.0
celest_core: ^0.3.0-dev.1
celest_core: ^0.3.0-dev.2
chunked_stream: ^1.4.2
corks_cedar: ^0.1.0
ffi: ^2.1.2
Expand Down
4 changes: 4 additions & 0 deletions packages/celest_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0-dev.2

- Add `signOut` method to `AuthProtocol` for clearing browser cookies

## 0.3.0-dev.1

- Adds `SecureStorage` interface for storage of sensitive data in the platform keychain
Expand Down
5 changes: 5 additions & 0 deletions packages/celest_core/lib/src/auth/auth_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ final class AuthClient with BaseProtocol implements AuthProtocol {
return User.fromJson(response);
}

@override
Future<void> signOut() async {
await postJson('/_auth/sign-out', {});
}

@override
late final EmailClient email = EmailClient(celest);
}
Expand Down
1 change: 1 addition & 0 deletions packages/celest_core/lib/src/auth/auth_protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ abstract interface class AuthProtocol {
EmailProtocol get email;

Future<User> userInfo();
Future<void> signOut();
}

abstract interface class EmailProtocol {
Expand Down
2 changes: 1 addition & 1 deletion packages/celest_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: celest_core
description: Celest types and utilities shared between the client and the cloud.
version: 0.3.0-dev.1
version: 0.3.0-dev.2
homepage: https://celest.dev
repository: https://github.com/celest-dev/celest/tree/main/packages/celest_core

Expand Down

0 comments on commit c72b9ea

Please sign in to comment.