In this episode, we focus on one of the key requirements for getting Laravel Sanctum authentication working properly: making sure that both our frontend (the client) and backend (the API) are running on the same domain.
We start by talking about how, in local development, the frontend (for example, using Vue) often runs on localhost with a random port, while the backend might use something like Laravel Herd or Valet, which uses a custom domain like your-app.test
.
The main task here is to configure our client-side project to use the same base domain as the backend API, even if the port numbers are different. We walk through how to change the dev server configuration in our project's config file so that the client runs on the matching .test
domain locally.
After making this change, we restart the frontend server and confirm that it's accessible via the new domain. This setup is very important—if the domains don’t match, Sanctum authentication simply won’t work! This episode gets us past this common stumbling block and sets us up for smooth auth testing moving forward.