Introduction
Build a secure SPA using Laravel 12 backend API with Passport OAuth2 authentication and Vue 3 frontend in a single project.
Unlike Sanctum (cookie-based), this uses API tokens (Bearer tokens) and OAuth2 flow.
Why Laravel Passport?
✅ Industry-standard OAuth2 API authentication
✅ Token-based (mobile apps, third-party APIs ready)
✅ Secure access tokens and refresh tokens
✅ Works well with SPA and mobile clients
✅ Full OAuth2 server implementation
What You Will Build
-
User Registration & Login via API (Passport)
-
Authenticated User Profile
-
Logout (token revocation)
-
Protected API routes with middleware
-
Vue 3 SPA frontend with Vue Router + Pinia
-
Laravel 12 API backend with Passport
Prerequisites
-
PHP 8.1+
-
Composer
-
Node.js & npm
-
MySQL
-
Basic Laravel & Vue knowledge
Step 1: Create Laravel Project
Step 2: Setup Database
Create MySQL database laravel_vue_passport.
Edit .env:
Step 3: Install Laravel Passport
Publish Passport migrations and config:
Step 4: Configure User Model for Passport
Edit app/Models/User.php:
Step 5: Configure Auth Config
Edit config/auth.php:
Step 6: Setup API Auth Controller
Generate:
Edit app/Http/Controllers/API/AuthController.php:
Step 7: Create Form Request Validations
Edit app/Http/Requests/RegisterRequest.php:
Edit app/Http/Requests/LoginRequest.php:
Step 8: Create User API Resource
Edit app/Http/Resources/UserResource.php:
Step 9: Define API Routes
Edit routes/api.php:
Step 10: Create Vue Project Directories & Files
Step 11: Install Vue 3 Dependencies
Step 12: Configure Vite
Edit vite.config.js:
Step 13: Vue Router Setup
Edit resources/js/router/index.js:
Step 14: Pinia Store Setup
Edit resources/js/stores/auth.js:
Step 15: API Service Helper
Edit resources/js/services/api.js:
Step 16: Vue Entry Point
Edit resources/js/app.js:
Step 17: Main Vue Component
Edit resources/js/App.vue:
Step 18: Vue Components (Login, Register, Dashboard)
Login.vue
Register.vue
Dashboard.vue
Step 19: Blade View to Load Vue SPA
Edit routes/web.php:
Create resources/views/welcome.blade.php:
Step 20: Run Your Project
Open two terminals:
Start Laravel backend:
Start frontend dev server:
Step 21: Visit Your App
Open browser:
You now have a secure SPA with:
-
Laravel 12 API backend using Passport OAuth2
-
Vue 3 SPA frontend with Vue Router + Pinia
-
API token-based authentication with Bearer tokens
-
Login, registration, user profile, logout, protected API routes
Summary
This tutorial uses Passport instead of Sanctum for API authentication. You get Bearer tokens stored in localStorage and sent via headers.

