initialize method

Future<String?> initialize()

Initializes TOTP: generates secret if missing, logs QR-compatible URI. Embedded secrets from --dart-define are used in release mode or when both parts are provided (so local testing matches CI/release builds).

Implementation

Future<String?> initialize() async {
  if (kReleaseMode || ReleaseConfig.hasEmbeddedSecret) {
    log('TOTP secret (embedded via dart-define, release=$kReleaseMode)');
    _cachedSecret = ReleaseConfig.totpSecret;
  } else {
    _cachedSecret ??= await _storage.read(key: _secretKey);

    if (_cachedSecret == null) {
      _cachedSecret = _generateBase32Secret();
      await _storage.write(key: _secretKey, value: _cachedSecret!);
      final uri = _buildOtpAuthUri(_cachedSecret!);
      log(
        'Debug Overlay TOTP setup complete!\n'
        'Scan this URI in Google Authenticator:\n$uri',
      );
    } else {
      log('Debug Overlay TOTP secret already exists. => $_cachedSecret');
    }
  }
  return _cachedSecret;
}