I'm using laravel's defult auth system but I'm sending requests threw ajax. If I am for example on login page and I send some wrong data, it throws me an error into console:
POST http://some.app/auth/login/ 422 (Unprocessable Entity)
but actually it returns some data:
email: ["The email must be a valid email address."]
Same weird acting for registration.
1. how to fix those status codes?
2. how to handle those errors? Just writing data.email and data.password to an user? Isn't there a better solution?
3. what about csrf token? I'm sending it with data but it doesn't seem to require that
Thanks
This is a validation error.
The information is returned to the $errors
variable. You can handle that any way you want but I guess the most obvious action would be to show the error to the user.
Actually it's better to have a 422 than a 200 (everything OK, for it's not). Since the auth system relies on the validation request, you wouldn't want the controller to proceed (eg by saving data that didn't pass validation).