diff --git a/apps/cli/lib/src/commands/auth/login_command.dart b/apps/cli/lib/src/commands/auth/login_command.dart index 484b620bb..c8b6240df 100644 --- a/apps/cli/lib/src/commands/auth/login_command.dart +++ b/apps/cli/lib/src/commands/auth/login_command.dart @@ -5,9 +5,11 @@ import 'package:celest_cli/src/commands/auth/cli_auth.dart'; import 'package:celest_cli/src/commands/celest_command.dart'; import 'package:celest_cli/src/context.dart'; import 'package:celest_cli/src/exceptions.dart'; +import 'package:celest_cli/src/repositories/cloud_repository.dart'; import 'package:corks_cedar/corks_cedar.dart'; -final class LoginCommand extends CelestCommand with Authenticate { +final class LoginCommand extends CelestCommand + with Authenticate, CloudRepository { LoginCommand() { argParser.addOption( 'token', @@ -47,6 +49,16 @@ final class LoginCommand extends CelestCommand with Authenticate { throw CliException('Failed to authenticate with token.'); } + Future _ensurePrimaryOrg() async { + final primaryOrg = await primaryOrganization; + if (primaryOrg != null) { + logger.finest('Primary organization: ${primaryOrg.displayName}'); + return; + } + cliLogger.success('Welcome to Celest Cloud!'); + await createPrimaryOrg(); + } + @override Future run() async { await super.run(); @@ -68,6 +80,7 @@ final class LoginCommand extends CelestCommand with Authenticate { if (res != 0) { return res; } + await _ensurePrimaryOrg(); cliLogger.success('You have been logged in!'); } diff --git a/apps/cli/pubspec.yaml b/apps/cli/pubspec.yaml index 9abc53895..39c263872 100644 --- a/apps/cli/pubspec.yaml +++ b/apps/cli/pubspec.yaml @@ -22,6 +22,7 @@ dependencies: celest_auth: ^1.0.0 celest_cloud: ^0.1.5-0 celest_cloud_auth: ^0.3.0-0 + celest_cloud_core: ^0.1.0 celest_core: ^1.0.0 chunked_stream: ^1.4.2 cli_script: ^1.0.0