run method

  1. @override
Future<void>? run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<void>? run() async {
  try {
    print('Enter your email');
    final email = ask('email:');

    if (!isValidEmail(email)) {
      throw Exception('❌ Invalid email');
    }

    final result = await showLoader(
      _authRepository.requestCredentials(email),
    );
    result.whenOrNull(
      failed: (statusCode, data) {
        throw Exception(
          '$statusCode: ${data is Map ? data['message'] : 'Internal error'}',
        );
      },
    );

    print(
      '✅ We have sent an email with your auth credentials\nEnter your credentials',
    );

    final sessionResult = await showLoader(
      _authRepository.sendCredentials(
        email: email,
        apiKey: ask('apiKey:').trim(),
        oobCode: ask('oobCode:').trim(),
      ),
    );

    sessionResult.whenOrNull(
      failed: (statusCode, data) {
        throw Exception(
          '$statusCode: ${data is Map ? data['message'] : 'Internal error'}',
        );
      },
    );

    print('✅ Session saved');
    exit(0);
  } catch (e) {
    print(e);
    exit(1);
  }
}