Auth Service Testing Guide
This guide explains how to implement and test the auth.do.dev unified authentication service.
Prerequisites
-
Environment Variables: Ensure the auth Convex deployment variables are in your root
.env.local:# Auth Convex Deployment CONVEX_DEPLOYMENT_AUTH="dev:dependable-pika-747" NEXT_PUBLIC_CONVEX_URL_AUTH="https://dependable-pika-747.convex.cloud" -
Convex Environment Variables: Set these in the Convex dashboard for the auth deployment:
# Email provider RESEND_API_KEY=re_xxxxxxxxxxxx AUTH_RESEND_FROM=auth@notifications.do.dev # OAuth providers (optional for initial testing) AUTH_GITHUB_ID=xxxxxxxxxxxx AUTH_GITHUB_SECRET=xxxxxxxxxxxx AUTH_GOOGLE_ID=xxxxxxxxxxxx.apps.googleusercontent.com AUTH_GOOGLE_SECRET=xxxxxxxxxxxx # JWT Secret JWT_SECRET=your-random-jwt-secret-string
Development Setup
1. Install Dependencies
# From root directory
pnpm install2. Initialize the Auth Database
Start the auth Convex development server to initialize the schema:
# Option 1: Run auth service with its Convex backend
pnpm convex:auth:dev
# Option 2: In a separate terminal, run just the auth Convex
cd apps/auth
npx convex devThis will:
- Initialize the database schema
- Generate TypeScript types
- Start the Convex development server
3. Create the Auth App Structure
The auth app should be created in apps/auth/ with this structure:
apps/auth/
├── app/
│ ├── api/
│ │ └── auth/
│ │ ├── validate/route.ts
│ │ ├── refresh/route.ts
│ │ └── oauth/
│ │ ├── google/route.ts
│ │ └── github/route.ts
│ ├── login/page.tsx
│ ├── verify/page.tsx
│ └── layout.tsx
├── components/
│ ├── auth-form.tsx
│ ├── verify-code.tsx
│ └── oauth-buttons.tsx
├── convex/
│ ├── schema.ts
│ ├── auth.ts
│ └── _generated/
└── lib/
└── utils.ts4. Start Development Servers
You'll need multiple terminal windows:
# Terminal 1: Auth Convex backend
cd apps/auth
npx convex dev
# Terminal 2: Auth Next.js app
cd apps/auth
pnpm dev --port 3001
# Terminal 3: Main dodev app (for testing integration)
cd apps/dodev
pnpm dev --port 3005Testing Flows
1. Email OTP Authentication
Test Setup
- Ensure Resend API key is configured in Convex environment
- Navigate to
http://localhost:3001/login?app=dodev&return=http://localhost:3005/dashboard
Test Steps
- Enter Email: Enter a valid email address
- Check Email: Look for OTP code in your email
- Verify Code: Enter the 6-digit code
- Check Redirect: Should redirect to the return URL with auth token
Expected Behavior
- Email sent within 30 seconds
- Code valid for 10 minutes
- Successful verification creates session
- Redirect includes auth token in cookie or URL
2. OAuth Authentication
Google OAuth Test
- Configure Google OAuth credentials in Convex
- Navigate to auth page with Google button
- Click "Continue with Google"
- Complete Google OAuth flow
- Verify redirect to return URL
GitHub OAuth Test
- Configure GitHub OAuth credentials in Convex
- Navigate to auth page with GitHub button
- Click "Continue with GitHub"
- Complete GitHub OAuth flow
- Verify redirect to return URL
3. Session Validation
Test the Validation API
# Get a valid token from login flow, then test validation
curl -X POST http://localhost:3001/api/auth/validate \
-H "Content-Type: application/json" \
-d '{"token": "your-session-token"}'Expected Response
{
"valid": true,
"user": {
"id": "user-id",
"email": "user@example.com",
"name": "User Name"
},
"session": {
"appId": "dodev",
"expiresAt": 1234567890000
}
}4. Integration Testing with dodev App
Setup Integration
-
Install the auth client package:
cd apps/dodev pnpm add @workspace/auth-client -
Add the auth client hook to dodev:
// apps/dodev/hooks/use-auth.ts import { useUnifiedAuth } from '@workspace/auth-client' export function useAuth() { return useUnifiedAuth() } -
Test the integration:
# Start both services cd apps/auth && pnpm dev --port 3001 & cd apps/dodev && pnpm dev --port 3005 &
Integration Test Flow
- Visit
http://localhost:3005(dodev app) - Click login/signup button
- Should redirect to
http://localhost:3001/login?app=dodev&return=http://localhost:3005/dashboard - Complete auth flow
- Should redirect back to dodev with valid session
Error Testing
1. Invalid Tokens
# Test with invalid token
curl -X POST http://localhost:3001/api/auth/validate \
-H "Content-Type: application/json" \
-d '{"token": "invalid-token"}'
# Expected: 401 Unauthorized2. Expired Tokens
- Create a session
- Wait for token to expire (or manually expire in database)
- Test validation - should return invalid
3. Invalid OTP Codes
- Start email flow
- Enter incorrect OTP code
- Should show error message
- Allow retry up to 3 times
4. Rate Limiting
- Attempt multiple rapid login attempts
- Should be rate limited after threshold
- Should return appropriate error message
Debugging
Common Issues
"Convex deployment not found"
# Check deployment configuration
cd apps/auth
cat .env.local | grep CONVEX
npx convex dashboard"Email not sending"
# Check Resend configuration
npx convex env list
# Look for RESEND_API_KEY and AUTH_RESEND_FROM"OAuth redirect mismatch"
- Check OAuth app configuration in Google/GitHub
- Ensure redirect URLs match exactly
- Check for port mismatches in development
Logging
Enable detailed logging for debugging:
// In Convex functions, add logging
console.log("Auth attempt:", { email, timestamp: Date.now() });View logs in Convex dashboard or terminal where npx convex dev is running.
Production Deployment
1. Environment Configuration
Set production environment variables in:
- Convex dashboard for the auth deployment
- Vercel for the auth Next.js app
2. Domain Setup
- Configure
auth.do.devDNS - Set up SSL certificate
- Update OAuth app redirect URLs
3. Monitoring
Set up monitoring for:
- Auth success/failure rates
- Email delivery rates
- OAuth flow completion rates
- Session validation rates
Security Checklist
Development
- Use HTTPS in development (mkcert recommended)
- Never commit secrets to version control
- Use secure JWT secrets (32+ characters)
- Implement proper CORS policies
Production
- Use production OAuth credentials
- Enable webhook signature verification
- Implement rate limiting
- Set up monitoring and alerting
- Use production email domain
- Implement proper session management
Next Steps
- Complete Implementation: Finish auth app based on design document
- Integration Testing: Test with all target apps (dodev, promptnow, etc.)
- Performance Testing: Load test with multiple concurrent users
- Security Audit: Review implementation for security issues
- Documentation: Update API documentation
- Migration: Plan migration from existing auth systems