fix: OTP chat muestra error visible cuando falla el envío de correo
- 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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
5c7c8c8a95
commit
e804831e15
@@ -41,6 +41,7 @@ class PublicChat extends Component
|
|||||||
public string $celularRegistro = '';
|
public string $celularRegistro = '';
|
||||||
public string $codigoIngresado = '';
|
public string $codigoIngresado = '';
|
||||||
public ?string $emailMascarado = null;
|
public ?string $emailMascarado = null;
|
||||||
|
public ?string $errorEnvioOtp = null;
|
||||||
public ?int $contactIdPending = null; // contact.id mientras espera verificacion
|
public ?int $contactIdPending = null; // contact.id mientras espera verificacion
|
||||||
public string $input = '';
|
public string $input = '';
|
||||||
public array $mensajes = [];
|
public array $mensajes = [];
|
||||||
@@ -262,15 +263,23 @@ class PublicChat extends Component
|
|||||||
// Paso 2b: verificar código OTP
|
// 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);
|
$codigo = (string) random_int(100000, 999999);
|
||||||
Cache::put("chat_otp_{$contactId}", $codigo, now()->addMinutes(10));
|
Cache::put("chat_otp_{$contactId}", $codigo, now()->addMinutes(10));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Mail::to($user->email)->send(new ChatOtpMail($codigo, $user->name));
|
Mail::to($user->email)->send(new ChatOtpMail($codigo, $user->name));
|
||||||
|
$this->errorEnvioOtp = null;
|
||||||
|
return true;
|
||||||
} catch (\Throwable $e) {
|
} 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);
|
$user = User::find($contact->user_id);
|
||||||
if ($user) {
|
if ($user) {
|
||||||
$this->enviarCodigoOtp($this->contactIdPending, $user);
|
$ok = $this->enviarCodigoOtp($this->contactIdPending, $user);
|
||||||
session()->flash('otp_reenviado', 'Codigo reenviado a tu correo.');
|
if ($ok) {
|
||||||
|
session()->flash('otp_reenviado', 'Código reenviado a tu correo.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,12 @@
|
|||||||
<p class="text-[#00a884] text-sm text-center mb-3">{{ session('otp_reenviado') }}</p>
|
<p class="text-[#00a884] text-sm text-center mb-3">{{ session('otp_reenviado') }}</p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if ($errorEnvioOtp)
|
||||||
|
<div class="bg-red-900/40 border border-red-500/50 rounded-xl px-4 py-3 mb-3 text-red-300 text-sm text-center">
|
||||||
|
{{ $errorEnvioOtp }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<form wire:submit.prevent="verificarCodigo" class="space-y-4">
|
<form wire:submit.prevent="verificarCodigo" class="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-[#8696a0] text-xs font-medium mb-1.5 uppercase tracking-wider">Código de verificación</label>
|
<label class="block text-[#8696a0] text-xs font-medium mb-1.5 uppercase tracking-wider">Código de verificación</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user