Skip to content

Commit

Permalink
feat: add validation for empty options while setting two factor auth (#…
Browse files Browse the repository at this point in the history
…52)

* feat: add validation for empty options while setting two factor auth

* test fixing phpstan

* fixing phpstan

* having difficulties fixing this phpstan thing :S
  • Loading branch information
lucascnunes authored Nov 14, 2024
1 parent 5b37aca commit 5a9d426
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Pages/TwoFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ public function mount(): void
->send();
}

$this->twoFactorOptionsCount = config('filament-2fa.options') ? count(config('filament-2fa.options')) : 0;
if (config('filament-2fa.options')) {
$this->twoFactorOptionsCount = count(config('filament-2fa.options'));
} else {
$this->twoFactorOptionsCount = 0;
}

$this->user = Auth::user();

Expand Down Expand Up @@ -107,7 +111,7 @@ public function twoFactorOptionForm(Form $form): Form
TwoFactorType::authenticator,
]);

/** @var Collection<int, TwoFactorType> $collection */
/** @var Collection<int,TwoFactorType> $collection */
$collection = collect($configOptions);

/** @var array<string, string> $options */
Expand Down Expand Up @@ -193,11 +197,19 @@ public function enableAction(): Action
$formData['email'] = $data['email'];
}

if ($this->twoFactorData['option']) {
$formData['two_factor_type'] = TwoFactorType::tryFrom($this->twoFactorData['option']);
}
try {
if ($this->twoFactorData['option']) {
$formData['two_factor_type'] = TwoFactorType::tryFrom($this->twoFactorData['option']);
}
} catch (\Exception $e) {
Notification::make()
->title('Error!')
->body(__('Please select a method of authentication.'))
->danger()
->send();
return;
} /** @var array{two_factor_type: TwoFactorType|null, email?: mixed} $formData */

/** @var array{two_factor_type: TwoFactorType|null, email?: mixed} $formData */
if (
isset($formData['two_factor_type']) &&
($formData['two_factor_type'] === TwoFactorType::email || $formData['two_factor_type'] === TwoFactorType::phone)
Expand Down

0 comments on commit 5a9d426

Please sign in to comment.