Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
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
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()
lucascnunes marked this conversation as resolved.
Show resolved Hide resolved
->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