Authentication
VizBoard implements a robust authentication system using NextAuth.js v5 with multiple authentication strategies.Authentication Providers
VizBoard supports three authentication methods:Credentials
Email and password authentication with bcrypt hashing
Google OAuth
OAuth 2.0 authentication via Google
GitHub OAuth
OAuth 2.0 authentication via GitHub
Session Management
Sessions are managed using JWT (JSON Web Tokens) with the following configuration:src/lib/auth/auth.ts
JWT sessions are stateless and don’t require database lookups on every request, improving performance while maintaining security.
Password Security
Passwords are hashed using bcrypt with a salt rounds value of 10:Authorization
Route Protection
VizBoard uses NextAuth middleware to protect routes automatically:src/app/middleware.ts
API Route Authorization
API routes verify user sessions and enforce ownership-based access control:src/app/api/widgets/[widgetId]/route.ts
Every resource query includes a
userId check to ensure users can only access their own data.Server Action Authorization
Server actions verify both project existence and user ownership:src/app/actions/project/validation.ts
Input Validation
Schema Validation with Zod
All user inputs are validated using Zod schemas before processing:Validation in Server Actions
src/app/actions/project/validation.ts
Environment Variables
Required Security Variables
VizBoard requires the following environment variables for secure operation:| Variable | Purpose | Format |
|---|---|---|
ENCRYPTION_KEY | AES-256-GCM encryption key for database credentials | 64-character hex string (32 bytes) |
AUTH_GOOGLE_ID | Google OAuth client ID | String |
AUTH_GOOGLE_SECRET | Google OAuth client secret | String |
AUTH_GITHUB_ID | GitHub OAuth client ID | String |
AUTH_GITHUB_SECRET | GitHub OAuth client secret | String |
NEXTAUTH_URL | Base URL for authentication callbacks | URL |
NEXTAUTH_SECRET | Secret for signing tokens | String |
Environment Variable Validation
The application validates required environment variables at startup:src/lib/crypto/crypto.ts
src/lib/auth/auth.ts
Security Best Practices
1. Data Encryption
Sensitive Data Protection
All database credentials are encrypted at rest using AES-256-GCM. See the Encryption page for implementation details.
2. Error Handling
Avoid leaking sensitive information in error messages:src/lib/auth/auth.ts
Detailed error logs are only shown in development. Production returns generic error messages to prevent information disclosure.
3. OAuth vs Credentials
The system prevents credential-based login for OAuth users:src/lib/auth/auth.ts
4. Session Token Management
JWT tokens are refreshed on each request and include user data:src/lib/auth/auth.ts
5. Email Normalization
All email addresses are normalized to lowercase to prevent duplicate accounts:src/app/actions/auth/signUp.ts
Related Documentation
Encryption
Learn about AES-256-GCM encryption for database credentials
API Development
Build secure API endpoints with proper authorization
