Day 5

Updating the request data to send what Laravel expects

I get a 422 from the /api/register endpoint when sending this data:

{ "email": "[email protected]", "password": "bbbbbb", "username": "a" }

The response helpfully tells me

{
	"message": "The name field is required. (and 2 more errors)",
	"errors": {
		"name": ["The name field is required."],
		"password": [
			"The password field confirmation does not match.",
			"The password field must be at least 8 characters."
		]
	}
}

+1 for developer experience because the data is validated out of the box and clear error messages are provided.

The fix

This required 3 updates to fix:

  1. Change the username param to name
  2. Add the password_confirmation param that Laravel expects and compares against the password param
  3. Update my error message to match the error message that Laravel provides

It’s now creating users!! I confirmed the user was in the database.

Next steps

Next I’ll tackle the login flow.