feat: Implement robust error handling and logging for user registration, displaying an error toast on failure.
This commit is contained in:
parent
7df0e16914
commit
a12e516b2d
@ -72,11 +72,13 @@ public function updated(string $propertyName, mixed $value): void
|
|||||||
|
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
$this->form->auth();
|
if ($this->form->auth()) {
|
||||||
|
|
||||||
$this->sendRegistrationSuccessToast();
|
$this->sendRegistrationSuccessToast();
|
||||||
$this->notifyPrivilegedUsersAboutNewMember();
|
$this->notifyPrivilegedUsersAboutNewMember();
|
||||||
$this->redirectAfterRegistration();
|
$this->redirectAfterRegistration();
|
||||||
|
} else {
|
||||||
|
$this->toast('Terjadi kesalahan saat mendaftarkan akun. Silakan hubungi admin atau coba beberapa saat lagi.', 'Kesalahan', 'danger');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render(): View
|
public function render(): View
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\Rules\Password;
|
use Illuminate\Validation\Rules\Password;
|
||||||
use Livewire\Form;
|
use Livewire\Form;
|
||||||
@ -92,7 +93,7 @@ public function validationAttributes(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function auth(): string
|
public function auth(): ?string
|
||||||
{
|
{
|
||||||
$this->validateAll();
|
$this->validateAll();
|
||||||
|
|
||||||
@ -101,6 +102,7 @@ public function auth(): string
|
|||||||
$referralCode = ReferralCode::where('code', $this->referral_code)->first();
|
$referralCode = ReferralCode::where('code', $this->referral_code)->first();
|
||||||
|
|
||||||
$user = null;
|
$user = null;
|
||||||
|
try {
|
||||||
DB::transaction(function () use ($tier, $maxUser, $referralCode, &$user): void {
|
DB::transaction(function () use ($tier, $maxUser, $referralCode, &$user): void {
|
||||||
$user = User::create([
|
$user = User::create([
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
@ -152,5 +154,14 @@ public function auth(): string
|
|||||||
});
|
});
|
||||||
|
|
||||||
return $this->name;
|
return $this->name;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Registration Error: '.$e->getMessage(), [
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
'email' => $this->email,
|
||||||
|
'username' => $this->username,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user