From e804831e15c0cc2d8dce44c16890d463d24fd431 Mon Sep 17 00:00:00 2001 From: Lizandro Date: Sun, 19 Jul 2026 21:11:21 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20OTP=20chat=20muestra=20error=20visible?= =?UTF-8?q?=20cuando=20falla=20el=20env=C3=ADo=20de=20correo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - enviarCodigoOtp retorna bool y loguea excepción completa con driver/host - $errorEnvioOtp prop pública: se muestra en UI si el correo falla - reenviarCodigo sólo muestra "reenviado" si el envío fue exitoso Co-Authored-By: Claude Sonnet 4.6 --- app/Http/Livewire/Chat/PublicChat.php | 19 +++++++++++++++---- .../views/livewire/chat/public-chat.blade.php | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/Http/Livewire/Chat/PublicChat.php b/app/Http/Livewire/Chat/PublicChat.php index 07af6dd..f80c915 100755 --- a/app/Http/Livewire/Chat/PublicChat.php +++ b/app/Http/Livewire/Chat/PublicChat.php @@ -41,6 +41,7 @@ class PublicChat extends Component public string $celularRegistro = ''; public string $codigoIngresado = ''; public ?string $emailMascarado = null; + public ?string $errorEnvioOtp = null; public ?int $contactIdPending = null; // contact.id mientras espera verificacion public string $input = ''; public array $mensajes = []; @@ -262,15 +263,23 @@ class PublicChat extends Component // Paso 2b: verificar código OTP // ───────────────────────────────────────────────────────── - private function enviarCodigoOtp(int $contactId, User $user): void + private function enviarCodigoOtp(int $contactId, User $user): bool { $codigo = (string) random_int(100000, 999999); Cache::put("chat_otp_{$contactId}", $codigo, now()->addMinutes(10)); try { Mail::to($user->email)->send(new ChatOtpMail($codigo, $user->name)); + $this->errorEnvioOtp = null; + return true; } catch (\Throwable $e) { - \Illuminate\Support\Facades\Log::warning('[ChatOTP] Error enviando correo: ' . $e->getMessage()); + \Illuminate\Support\Facades\Log::error('[ChatOTP] Error enviando correo a ' . $user->email . ': ' . $e->getMessage(), [ + 'exception' => $e, + 'mailer' => config('mail.default'), + 'host' => config('mail.mailers.smtp.host'), + ]); + $this->errorEnvioOtp = 'No pudimos enviar el correo. Verifica tu email o intenta reenviar.'; + return false; } } @@ -321,8 +330,10 @@ class PublicChat extends Component $user = User::find($contact->user_id); if ($user) { - $this->enviarCodigoOtp($this->contactIdPending, $user); - session()->flash('otp_reenviado', 'Codigo reenviado a tu correo.'); + $ok = $this->enviarCodigoOtp($this->contactIdPending, $user); + if ($ok) { + session()->flash('otp_reenviado', 'Código reenviado a tu correo.'); + } } } diff --git a/resources/views/livewire/chat/public-chat.blade.php b/resources/views/livewire/chat/public-chat.blade.php index ff7e4e0..e2de411 100755 --- a/resources/views/livewire/chat/public-chat.blade.php +++ b/resources/views/livewire/chat/public-chat.blade.php @@ -118,6 +118,12 @@

{{ session('otp_reenviado') }}

@endif + @if ($errorEnvioOtp) +
+ {{ $errorEnvioOtp }} +
+ @endif +