How is this not being caught by validation? How are you actually trying to create the User?
Apr 4, 2022
17
Level 12
Handling duplicate key value violates unique constraint error
Hey!
When trying to register with an email that exists in the database I'm getting the following error:
SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "users_email_unique" DETAIL: Key (email)=([email protected]) already exists.
how can I change this error page to appear as a validation error (alert) and not a query exception? Something like: This email has already been registered
Here's my validation inside app/Actions/Fortify/CreateNewUser.php
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => $this->passwordRules(),
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['required', 'accepted'] : '',
'g-recaptcha-response' => 'required|recaptcha',
],
[
'g-recaptcha-response.required' => 'The robot check is required.',
'g-recaptcha-response.recaptcha' => 'Captcha verification failed!'
])->validate();
Level 39
When I try to register with [email protected]
I'm getting a error page ... values (haha, [email protected], ...
Your code converts input in lower case after the validation logic and this lower case email still exists in the db.
Please or to participate in this conversation.
