Skip to content
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
15 changes: 14 additions & 1 deletion apps/cli/lib/src/commands/auth/login_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -47,6 +49,16 @@ final class LoginCommand extends CelestCommand with Authenticate {
throw CliException('Failed to authenticate with token.');
}

Future<void> _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<int> run() async {
await super.run();
Expand All @@ -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!');
}

Expand Down
1 change: 1 addition & 0 deletions apps/cli/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down