Skip to content

Commit d5cf29a

Browse files
authored
refactor(cloud_auth)!: Consolidate session logic (#273)
- Adds new repos for sessions and users to consolidate logic and DB operations - Makes all tokens issued by AuthenticationService be "session tokens" - Effectively, this makes all "identity tokens" now "access tokens" instead - Adds DB migrations for column changes
1 parent 4360e18 commit d5cf29a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+12838
-651
lines changed

apps/cli/lib/src/pub/project_dependency.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ final class ProjectDependency {
9797
'celest_cloud_auth',
9898
DependencyType.dependency,
9999
HostedDependency(
100-
version: VersionConstraint.compatibleWith(Version.parse('0.1.0')),
100+
version: VersionConstraint.compatibleWith(Version.parse('0.2.0')),
101101
),
102102
);
103103

apps/cli/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies:
2020
celest: ^1.0.0
2121
celest_ast: ^0.1.4
2222
celest_auth: ^1.0.0
23-
celest_cloud_auth: ^0.1.0
23+
celest_cloud_auth: ^0.2.0-0
2424
celest_core: ^1.0.0
2525
chunked_stream: ^1.4.2
2626
cli_script: ^1.0.0

packages/celest/build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ targets:
22
$default:
33
sources:
44
include:
5+
- 'lib/$lib$'
56
- 'test/runtime/data/**'

packages/celest_auth/example/integration_test/integration_test.dart

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ void main() {
2626
),
2727
findsOneWidget,
2828
);
29-
30-
// TODO(dnys1): Fix unhandled exception.
31-
final _ = tester.takeException();
32-
addTearDown(() {
33-
tester.takeException();
34-
});
3529
});
3630

3731
testWidgets('sends OTP code', (tester) async {
@@ -101,12 +95,10 @@ void main() {
10195
findsOneWidget,
10296
);
10397

104-
// TODO
105-
10698
// Sign out
107-
// await tester.tap(find.byKey(TestKeys.btnSignOut));
108-
// await tester.pumpAndSettle();
99+
await tester.tap(find.byKey(TestKeys.btnSignOut));
100+
await tester.pumpAndSettle();
109101

110-
// expect(find.byKey(TestKeys.txtSignedOut), findsOneWidget);
102+
expect(find.byKey(TestKeys.txtSignedOut), findsOneWidget);
111103
});
112104
}

packages/celest_auth/lib/src/auth_impl.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class AuthImpl implements Auth {
2929
celest_cloud.CelestCloud(
3030
authenticator: Authenticator(
3131
secureStorage: _storage.secure,
32-
onRevoke: signOut,
32+
onRevoke: _revokeSession,
3333
),
3434
uri: celest.baseUri,
3535
httpClient: celest.httpClient,
@@ -80,8 +80,7 @@ final class AuthImpl implements Auth {
8080
_authProviderSubs[type] = tokenSource.listen(
8181
(token) async {
8282
if (token == null) {
83-
_reset();
84-
_authStateController.add(const Unauthenticated());
83+
_revokeSession();
8584
return;
8685
}
8786
await secureStorage.write('cork', token);
@@ -113,18 +112,18 @@ final class AuthImpl implements Auth {
113112
return initialState;
114113
}
115114
if (localStorage.read('userId') == null) {
116-
_reset();
115+
_revokeSession();
117116
return const Unauthenticated();
118117
}
119118
try {
120119
final user = await cloud.users.get('users/me');
121120
initialState = Authenticated(user: user.toCelest());
122121
} on UnauthorizedException {
123122
initialState = const Unauthenticated();
124-
_reset();
123+
_revokeSession();
125124
} on NotFoundException {
126125
initialState = const Unauthenticated();
127-
_reset();
126+
_revokeSession();
128127
}
129128
return initialState;
130129
}
@@ -197,16 +196,16 @@ final class AuthImpl implements Auth {
197196
} on Object {
198197
// TODO(dnys1): Log error
199198
} finally {
200-
_reset();
201-
if (!_authStateController.isClosed) {
202-
_authStateController.add(const Unauthenticated());
203-
}
199+
_revokeSession();
204200
}
205201
}
206202

207-
void _reset() {
203+
void _revokeSession() {
208204
localStorage.delete('userId');
209-
secureStorage.delete('cork').ignore();
205+
unawaited(secureStorage.delete('cork'));
206+
if (_authState != null && !_authStateController.isClosed) {
207+
_authStateController.add(const Unauthenticated());
208+
}
210209
}
211210

212211
final CelestBase celest;

services/celest_cloud_auth/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 0.2.0-wip
2+
13
## 0.1.1
24

35
- fix: Ensure Cedar types are registered during seeding

services/celest_cloud_auth/Makefile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ lib/src/database/schema/*.drift.dart: lib/src/database/schema/*.drift
22
@echo "Generating Drift code..."
33
@dart run build_runner build --delete-conflicting-outputs
44

5-
drift_schema/*.json: lib/src/database/schema/*.drift.dart
6-
@echo "Generating schema JSON..."
7-
@mkdir -p drift_schema
8-
@dart run drift_dev schema dump lib/src/database/auth_database.dart drift_schema/
9-
10-
lib/src/database/schema_versions.dart: drift_schema/*.json
5+
lib/src/database/auth_database.steps.dart: lib/src/database/auth_database.dart lib/src/database/schema/*.drift.dart
116
@echo "Generating migration steps..."
12-
@dart run drift_dev schema steps drift_schema/ lib/src/database/schema_versions.dart
7+
@dart run drift_dev make-migrations
138

14-
drift: lib/src/database/schema_versions.dart
9+
drift: lib/src/database/auth_database.steps.dart
1510

1611
cedar: lib/src/authorization/cedar/*
1712
@echo "Generating Cedar code..."

services/celest_cloud_auth/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ analyzer:
88
exclude:
99
- '**/*.g.dart'
1010
- '**/*.drift.dart'
11+
- 'test/database/auth_database/generated'

services/celest_cloud_auth/build.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ targets:
88
drift_dev:analyzer:
99
enabled: true
1010
options: &options
11+
databases:
12+
auth_database: lib/src/database/auth_database.dart
13+
schema_dir: drift_schema/
14+
test_dir: test/database/
15+
1116
named_parameters: true
1217
store_date_time_values_as_text: false
1318

services/celest_cloud_auth/drift_schema/auth_database/drift_schema_v1.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)