This repository contains the source code for both a Laravel application and a Nuxt 3 application demonstrating authentication with Laravel Sanctum.
This demo walks through setting up Sanctum authentication, including both cookie-based and token-based authentication methods.
- Laravel backend with Sanctum authentication.
 - Nuxt 3 frontend configured with 
@qirolab/nuxt-sanctum-authenticationmodule. - SPA cookie-based authentication (default) and token-based authentication.
 - API route protection using Sanctum.
 
For a step-by-step guide, watch the full tutorial on YouTube:
This repository contains two different branches depending on the type of authentication you want to implement:
- 
Cookie-Based SPA Authentication: The default authentication mode using Laravel Sanctum cookies. You can check out the main branch for this implementation.
- Branch: 
main 
 - Branch: 
 - 
API Token-Based Authentication: If you prefer to use token-based authentication for your API, switch to the
api-token-authenticationbranch.- Branch: 
api-token-authentication 
 - Branch: 
 
Make sure to check out the correct branch depending on your use case.
git clone [email protected]:qirolab/nuxt-sanctum-authentication-demo.gitNavigate to the Laravel folder and install dependencies:
cd laravel-api
composer installCopy the .env.example to .env:
cp .env.example .envGenerate the application key:
php artisan key:generateSet up your database in the .env file and run migrations:
php artisan migrateRun the Laravel server:
php artisan serveNavigate to the Nuxt app folder and install dependencies:
cd nuxt3-app
npm installCopy the .env.example to .env:
cp .env.example .envMake sure to set the NUXT_SANCTUM_API_URL in your .env file to point to your Laravel app URL.
Run the Nuxt development server:
npm run dev- Open the Laravel app in your browser (default: 
http://localhost:8000). - Open the Nuxt app in your browser (default: 
http://localhost:3000). - Try logging in using the credentials you've set up in your Laravel app.
 
If you found this demo helpful and want to support my work, check out some of my other products:
This project is open-sourced software licensed under the MIT license.