A small Laravel Sanctum auth API with a static browser frontend for testing registration, login, authenticated user lookup, and logout.
backend/- Laravel API with Sanctum token authentication.frontend/- Static HTML, CSS, and JavaScript client.
- PHP 8.3 or newer
- Composer
- Python 3, only used to serve the static frontend locally
cd backend
composer install
php artisan migrate
php artisan serve --host=127.0.0.1 --port=8000The API will be available at:
http://127.0.0.1:8000/api
Open a second terminal:
cd frontend
python -m http.server 5173 --bind 127.0.0.1Then open:
http://127.0.0.1:5173/login.html
POST /api/register- Create a user and return a bearer token.POST /api/login- Sign in and return a bearer token.GET /api/me- Return the authenticated user.POST /api/logout- Revoke the current token.
Protected endpoints require:
Authorization: Bearer <token>
cd backend
php artisan test