Continuing from Step 1: https://www.webune.com/forums/laravel-two-commands-to-start-a-new-api-project.html
In this step, you will add backend user authentication as an API for SPA or mobile applications. Once you have completed step 2, you can complete step 3 which is adding authentication to the front end using React.
Open a Bash terminal in your Laravel root app and create two important folders:
$ mkdir app/Http/Controllers/Api; mkdir app/Http/Requests
curl -s https://www.webune.com/forums/AuthController.php.html > app/Http/Controllers/Api/AuthController.php
curl -s https://www.webune.com/forums/LoginRequest.php.html > app/Http/Requests/LoginRequest.php
curl -s https://www.webune.com/forums/SignupRequest.php.html > app/Http/Requests/SignupRequest.php
code app/Http/Controllers/Api/AuthController.php
code app/Http/Requests/LoginRequest.php
code app/Http/Requests/SignupRequest.php
echo done
IMPORTANT: You must remove the first three top lines to avoid errors of : AuthController.php, LoginRequest.php and SignupRequest.php
YOU SEE THIS ERROR: Namespace declaration statement has to be the very first statement or after any declare call in the script
$ code routes/api.php
Add:
$ code config/cors.php
Change the following Lines accoring to your requirements. For localhost test development, here is an example:
POST: http://localhost:8000/api/login
Body > form-data : Email:[email protected], password: test123
https://www.webune.com/forums/add-authentication-to-react-vite-using-laravel-backend.html