Skip to content

arpixnet/nuxt4-logto

Repository files navigation

Nuxt 4 Logto Boilerplate

Nuxt Logto Nuxt UI TypeScript

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.

✨ Features

πŸ” Logto Authentication

  • 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.)

πŸ‘€ Profile Management

  • 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

πŸ›‘οΈ Security

  • MFA/2FA with TOTP (Time-based One-Time Password)
  • 2FA setup and takedown with verification
  • Password change with validation
  • Danger zone for account deletion

πŸš€ API & Middleware

  • Middleware system for API routes
  • JWT token validation
  • Role-based access control (RBAC)
  • Rate limiting with Redis (in-memory fallback)
  • Automatic security headers

πŸ“Š Structured Logging

  • Logging system with Pino
  • Specialized loggers by context (auth, api, email, etc.)
  • Client-side logging with server forwarding
  • Automatic sensitive data redaction in production

🌐 Internationalization

  • Multi-language support with @nuxtjs/i18n
  • Included languages: Spanish and English
  • Automatic browser detection

πŸ“§ Emails

  • Integration with nuxt-arpix-email-sender
  • SMTP and Gmail OAuth2 support
  • Custom Handlebars templates
  • HTTP connector for Logto

πŸ“‹ Requirements

  • Node.js 18.x or higher
  • npm 9.x or higher
  • Docker (optional, for self-hosted Logto)
  • Redis (optional, for distributed rate limiting)

πŸš€ Quick Start

1. Create a new project

# 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 .env

2. Configure Logto

Option A: Logto Cloud (Recommended for production)

  1. Create an account at logto.io
  2. Create a "Traditional Web" application
  3. Configure redirect URIs: http://localhost:3000/callback
  4. 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:3002

3. Start development

npm run dev

The application will be available at http://localhost:3000.

βš™οΈ Configuration

Main Environment Variables

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.

πŸ“ Project Structure

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

πŸ“š Documentation

GraphQL and Hasura

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

Menu System

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

Internationalization (i18n)

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.

πŸ‘‰ View i18n documentation


API Middleware & Examples

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

Custom Profile Fields

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.

πŸ‘‰ Read custom fields guide

JWT Endpoint for Hasura

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

Pino Logging System

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.

πŸ‘‰ Explore logging guide

Redis Rate Limiting

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.

πŸ‘‰ View rate limiting guide

πŸ› οΈ Available Scripts

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

πŸ—οΈ Main Components

Composables

  • useAuthSession - Session and user data management
  • useUserProfile - Profile operations (update, delete)
  • useAvatarUpload - Avatar upload to MinIO/S3
  • useClientLogger - Client-side logging
  • usePasswordVisibility - Password visibility toggle

API Endpoints

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

🚒 Deployment

Production build

npm run build

Required environment variables in production

Make 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.

πŸ“„ License

MIT


Developed with ❀️ by Arpix Solutions

About

A production-ready Nuxt 4 boilerplate featuring Logto authentication with MFA support, Hasura GraphQL integration, user profile management with avatar upload, i18n (EN/ES), email templating, rate limiting, and complete Docker infrastructure (PostgreSQL, Redis, MinIO). Perfect starting point for modern SaaS applications.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors