Skip to content

Commit a36b8d2

Browse files
authored
feat(cli): Ensure primary org creation on login (#366)
Ensure that the primary organization exists when logging in or signing up.
1 parent e2337c3 commit a36b8d2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

apps/cli/lib/src/commands/auth/login_command.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import 'package:celest_cli/src/commands/auth/cli_auth.dart';
55
import 'package:celest_cli/src/commands/celest_command.dart';
66
import 'package:celest_cli/src/context.dart';
77
import 'package:celest_cli/src/exceptions.dart';
8+
import 'package:celest_cli/src/repositories/cloud_repository.dart';
89
import 'package:corks_cedar/corks_cedar.dart';
910

10-
final class LoginCommand extends CelestCommand with Authenticate {
11+
final class LoginCommand extends CelestCommand
12+
with Authenticate, CloudRepository {
1113
LoginCommand() {
1214
argParser.addOption(
1315
'token',
@@ -47,6 +49,16 @@ final class LoginCommand extends CelestCommand with Authenticate {
4749
throw CliException('Failed to authenticate with token.');
4850
}
4951

52+
Future<void> _ensurePrimaryOrg() async {
53+
final primaryOrg = await primaryOrganization;
54+
if (primaryOrg != null) {
55+
logger.finest('Primary organization: ${primaryOrg.displayName}');
56+
return;
57+
}
58+
cliLogger.success('Welcome to Celest Cloud!');
59+
await createPrimaryOrg();
60+
}
61+
5062
@override
5163
Future<int> run() async {
5264
await super.run();
@@ -68,6 +80,7 @@ final class LoginCommand extends CelestCommand with Authenticate {
6880
if (res != 0) {
6981
return res;
7082
}
83+
await _ensurePrimaryOrg();
7184
cliLogger.success('You have been logged in!');
7285
}
7386

apps/cli/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies:
2222
celest_auth: ^1.0.0
2323
celest_cloud: ^0.1.5-0
2424
celest_cloud_auth: ^0.3.0-0
25+
celest_cloud_core: ^0.1.0
2526
celest_core: ^1.0.0
2627
chunked_stream: ^1.4.2
2728
cli_script: ^1.0.0

0 commit comments

Comments
 (0)