Authentication Setup Guide
This guide explains how to properly configure authentication in your Ever Works application.
Required Environment Variables
Add these to your .env.local file:
# ============================================
# AUTHENTICATION & SECURITY
# ============================================
## Next Auth
AUTH_SECRET="your-generated-secret"
NEXTAUTH_SECRET="same-as-auth-secret"
NEXTAUTH_URL="http://localhost:3000"
Generating a Secure Secret
Run this command to generate a secure secret:
openssl rand -base64 32
Or use the NextAuth CLI:
npx auth secret
OAuth Provider Setup
To enable OAuth providers, add their credentials to your .env.local:
## OAuth Providers
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
FACEBOOK_CLIENT_ID=your_facebook_client_id
FACEBOOK_CLIENT_SECRET=your_facebook_client_secret
TWITTER_CLIENT_ID=your_twitter_client_id
TWITTER_CLIENT_SECRET=your_twitter_client_secret
Getting OAuth Credentials
Google OAuth
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Go to Credentials → Create Credentials → OAuth 2.0 Client ID
- Add authorized redirect URI:
http://localhost:3000/api/auth/callback/google - Copy Client ID and Client Secret
GitHub OAuth
- Go to GitHub Developer Settings
- Click "New OAuth App"
- Set Authorization callback URL:
http://localhost:3000/api/auth/callback/github - Copy Client ID and generate Client Secret
Facebook OAuth
- Go to Facebook Developers
- Create a new app
- Add Facebook Login product
- Set Valid OAuth Redirect URIs:
http://localhost:3000/api/auth/callback/facebook - Copy App ID and App Secret
ReCAPTCHA Setup
The template uses Google ReCAPTCHA v2 to protect forms from bots.
Configuration
Add these variables to your .env.local:
# ReCAPTCHA Configuration
NEXT_PUBLIC_RECAPTCHA_SITE_KEY="your-recaptcha-site-key"
RECAPTCHA_SECRET_KEY="your-recaptcha-secret-key"
Getting Keys
- Go to the Google ReCAPTCHA Console
- Create a new site
- Select reCAPTCHA v2 -> "I'm not a robot" Checkbox
- Add your domains (e.g.,
localhostfor dev,yourdomain.comfor prod) - Copy the Site Key (public) and Secret Key (private)
Usage
ReCAPTCHA is automatically enabled on authentication forms when the keys are present. To disable it for a specific form component:
<LoginForm showRecaptcha={false} />
Supabase Auth Setup (Optional)
If using Supabase Auth instead of or alongside NextAuth:
## Supabase
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
Common Issues and Solutions
1. MissingSecret Error
Error: MissingSecret: Please define a secret
Solution: Ensure both AUTH_SECRET and NEXTAUTH_SECRET are defined in your .env.local file.
# Verify environment variables are loaded
grep -E "AUTH_SECRET|NEXTAUTH" .env.local
2. JWTSessionError
Error: JWTSessionError: no matching decryption secret
Cause: This happens when the secret changes after session cookies were created.
Solution:
- Clear your browser cookies for localhost:3000
- Clear Next.js cache:
rm -rf .next/cache - Restart the development server
- Use incognito/private browsing mode for testing
3. OAuth Redirect Mismatch
Error: redirect_uri_mismatch
Solution: Ensure the redirect URI in your OAuth provider settings matches exactly:
- Development:
http://localhost:3000/api/auth/callback/[provider] - Production:
https://yourdomain.com/api/auth/callback/[provider]
4. Environment Variable Naming
The application uses both AUTH_SECRET (NextAuth v5) and NEXTAUTH_SECRET (NextAuth v4) for compatibility. Both should have the same value.
Development vs Production
Development
- The system can generate temporary secrets if missing (not recommended)
- Use
http://localhost:3000for NEXTAUTH_URL - Test mode for OAuth providers
Production
- All secrets MUST be properly configured
- Use your production domain for NEXTAUTH_URL
- Production OAuth credentials required
- HTTPS is mandatory
Security Best Practices
- Never commit secrets: Keep
.env.localin.gitignore - Use strong secrets: Always use cryptographically secure random values (32+ characters)
- Rotate secrets regularly: Change secrets periodically, especially after team changes
- Different secrets per environment: Use different secrets for dev/staging/production
- Secure storage: Use environment variable management tools (Vercel, AWS Secrets Manager, etc.)
- HTTPS in production: Always use HTTPS for production deployments
- Validate redirect URIs: Whitelist only necessary redirect URIs
Troubleshooting Steps
-
Verify environment variables are loaded:
grep -E "AUTH_SECRET|NEXTAUTH" .env.local -
Clear all caches:
rm -rf .next/cache
rm -rf .next/static -
Test in incognito mode to avoid cookie conflicts
-
Check logs for specific error messages in the terminal
-
Restart the development server after changing environment variables
-
Verify OAuth redirect URIs match exactly in provider settings
Next Steps
- Authentication Overview - Learn about the authentication architecture
- Environment Variables - Complete environment setup
- Deployment - Deploy your authenticated application
Need Help?
If you're still experiencing issues, check our support page or join our community.