Production-ready boilerplate for Nuxt 4 applications with complete authentication via Logto. Includes profile management, MFA/2FA, rate limiting, structured logging, and ready-to-use Hasura GraphQL integration.
- Complete integration with
@logto/nuxt - OAuth2/OIDC support
- Configured scopes: email, phone, custom_data, organizations, roles
- Secure sessions with encrypted cookies
- Social login support (Google, GitHub, etc.)
- Complete profile page with section navigation
- Personal data editing (name, username, phone)
- Custom fields via Logto's
custom_data - Avatar upload to MinIO/S3 with real-time preview
- MFA/2FA with TOTP (Time-based One-Time Password)
- 2FA setup and takedown with verification
- Password change with validation
- Danger zone for account deletion
- Middleware system for API routes
- JWT token validation
- Role-based access control (RBAC)
- Rate limiting with Redis (in-memory fallback)
- Automatic security headers
- Logging system with Pino
- Specialized loggers by context (auth, api, email, etc.)
- Client-side logging with server forwarding
- Automatic sensitive data redaction in production
- Multi-language support with
@nuxtjs/i18n - Included languages: Spanish and English
- Automatic browser detection
- Integration with
nuxt-arpix-email-sender - SMTP and Gmail OAuth2 support
- Custom Handlebars templates
- HTTP connector for Logto
- Node.js 18.x or higher
- npm 9.x or higher
- Docker (optional, for self-hosted Logto)
- Redis (optional, for distributed rate limiting)
# Create project from template
npx nuxi init my-project -t github:arpixnet/nuxt4-logto
# Navigate to project directory
cd my-project
# Install dependencies
npm install
# Copy environment variables
cp .env.example .envOption A: Logto Cloud (Recommended for production)
- Create an account at logto.io
- Create a "Traditional Web" application
- Configure redirect URIs:
http://localhost:3000/callback - Copy App ID, App Secret, and Endpoint to
.env
Option B: Self-hosted with Docker
# Start services
docker compose -f docker/docker-compose.yml up -d
# Access Admin Console at http://localhost:3002npm run devThe application will be available at http://localhost:3000.
| Variable | Description | Required |
|---|---|---|
NUXT_LOGTO_ENDPOINT |
Logto server URL | β |
NUXT_LOGTO_APP_ID |
Logto application ID | β |
NUXT_LOGTO_APP_SECRET |
Logto application secret | β |
NUXT_LOGTO_COOKIE_ENCRYPTION_KEY |
Encryption key (32+ chars) | β |
APP_NAME |
Application name | β |
BASE_URL |
Application base URL | β |
REDIS_HOST |
Redis host for rate limiting | β |
MINIO_* |
MinIO configuration for avatars | β |
See .env.example for the complete list of variables.
nuxt4-logto/
βββ app/ # Nuxt application
β βββ components/ # Vue components
β β βββ layout/ # Header, Footer, Logo, AuthUser
β β βββ profile/ # Profile components
β β βββ ui/ # Reusable UI components
β βββ composables/ # Vue composables
β βββ layouts/ # Page layouts
β βββ pages/ # Pages (auto-routing)
β βββ middleware/ # Route middleware
β βββ lib/ # Client-side utilities
βββ server/ # Nuxt server
β βββ api/ # API endpoints
β β βββ auth/ # Authentication (JWT)
β β βββ profile/ # Profile management
β β βββ avatar/ # Avatar uploads
β β βββ email/ # Email sending
β βββ middleware/ # Server middleware
β βββ utils/ # Server-side utilities
β βββ emails/ # Email templates
βββ shared/ # Shared types
βββ i18n/ # Translation files
βββ doc/ # Additional documentation
βββ docker/ # Docker configuration
Complete architecture for GraphQL integration with Hasura. Includes secure client with JWT authentication, reactive queries with useQuery, real-time subscriptions with WebSocket, and TokenManager for secure token management in memory.
π View GraphQL and Hasura documentation
Flexible menu system with support for horizontal, vertical, and footer variants. Includes role-based permissions, automatic i18n, external link detection, active state highlighting, and SSR-safe hydration.
π View Menu System documentation
Multi-language implementation with @nuxtjs/i18n. Covers configuration with no_prefix strategy, cookie-based language detection, component usage with useI18n(), SEO integration, and best practices for adding new languages.
The project includes a complete middleware system for API routes that provides JWT authentication, role-based authorization, rate limiting, and security headers. The documentation includes detailed examples of public, protected, and admin endpoints, along with usage patterns and error handling.
π View API Middleware examples
Logto allows storing additional user data in the custom_data field. This guide explains how to add new fields to the profile, update Zod validations, and maintain server synchronization. Includes important considerations about data overwriting and complete examples.
The /api/auth/jwt endpoint provides server-side access to the Logto ID token, enabling integration with external services like Hasura GraphQL Engine. The documentation covers token structure, usage examples with Hasura, expiration handling, and security considerations.
π View JWT endpoint documentation
The project uses Pino for structured logging on both server and client. Includes specialized loggers by context (auth, api, session, rate-limit, email), automatic sensitive data redaction in production, and a client-side composable to send critical logs to the server.
Rate limiting system based on rate-limiter-flexible with Redis support and automatic in-memory fallback. Allows limiting by user or IP, configuring limits per operation, and includes development tools to clear limits during testing.
| Command | Description |
|---|---|
npm run dev |
Development server |
npm run build |
Production build |
npm run preview |
Build preview |
npm run lint |
ESLint linting |
npm run typecheck |
Type checking |
useAuthSession- Session and user data managementuseUserProfile- Profile operations (update, delete)useAvatarUpload- Avatar upload to MinIO/S3useClientLogger- Client-side loggingusePasswordVisibility- Password visibility toggle
| Endpoint | Method | Description |
|---|---|---|
/api/auth/jwt |
GET | Get JWT token |
/api/profile/update |
PATCH | Update profile |
/api/profile/password |
PATCH | Change password |
/api/profile/account |
DELETE | Delete account |
/api/profile/mfa/* |
GET/POST/DELETE | MFA management |
/api/avatar/upload |
POST | Upload avatar |
/api/log |
POST | Receive client logs |
npm run buildMake sure to configure all NUXT_LOGTO_* variables pointing to your production Logto instance. Update redirect URIs in Logto Console to include your production domain.
For more information, see the Nuxt deployment documentation.
Developed with β€οΈ by Arpix Solutions