diff --git a/app/Http/Livewire/PrivateKey/Create.php b/app/Http/Livewire/PrivateKey/Create.php index cf8414b3e..4dcaedbe2 100644 --- a/app/Http/Livewire/PrivateKey/Create.php +++ b/app/Http/Livewire/PrivateKey/Create.php @@ -3,16 +3,20 @@ namespace App\Http\Livewire\PrivateKey; use App\Models\PrivateKey; +use DanHarrin\LivewireRateLimiting\WithRateLimiting; use Livewire\Component; use phpseclib3\Crypt\PublicKeyLoader; class Create extends Component { - public ?string $from = null; + use WithRateLimiting; public string $name; - public ?string $description = null; public string $value; + + public ?string $from = null; + public ?string $description = null; public ?string $publicKey = null; + protected $rules = [ 'name' => 'required|string', 'value' => 'required|string', @@ -24,9 +28,14 @@ class Create extends Component public function generateNewKey() { - $this->name = generate_random_name(); - $this->description = 'Created by Coolify'; - ['private' => $this->value, 'public' => $this->publicKey] = generateSSHKey(); + try { + $this->rateLimit(10); + $this->name = generate_random_name(); + $this->description = 'Created by Coolify'; + ['private' => $this->value, 'public' => $this->publicKey] = generateSSHKey(); + } catch(\Throwable $e) { + return handleError($e, $this); + } } public function updated($updateProperty) { @@ -34,7 +43,11 @@ public function updated($updateProperty) try { $this->publicKey = PublicKeyLoader::load($this->$updateProperty)->getPublicKey()->toString('OpenSSH',['comment' => '']); } catch (\Throwable $e) { - $this->publicKey = "Invalid private key"; + if ($this->$updateProperty === "") { + $this->publicKey = ""; + } else { + $this->publicKey = "Invalid private key"; + } } } $this->validateOnly($updateProperty); diff --git a/resources/views/components/forms/textarea.blade.php b/resources/views/components/forms/textarea.blade.php index be45629ab..bf0948605 100644 --- a/resources/views/components/forms/textarea.blade.php +++ b/resources/views/components/forms/textarea.blade.php @@ -30,7 +30,7 @@ class="w-4 h-4 stroke-current"> @endif