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/webs/auth
npx convex devThen initialize the apps table (one time only):
# In another terminal, while convex dev is running
cd apps/webs/auth
npx convex run apps:initialize
# You should see output like:
# { "initialized": 5 }3. Start the Auth Service
# Option 1: Run only the auth service
pnpm dev:auth
# Option 2: Run auth with core services
pnpm dev:core
# Option 3: Run all services including auth
pnpm dev:allThe auth service will be available at http://localhost:3030
Testing Scenarios
1. Basic Email Authentication
- Navigate to
http://localhost:3030 - Enter your email address
- Check your email for the 6-digit verification code
- Enter the code to complete sign-in
- You should be redirected to the dashboard
2. OAuth Authentication (GitHub/Google)
Note: OAuth requires proper configuration in the Convex dashboard first.
- Navigate to
http://localhost:3030 - Click "Continue with GitHub" or "Continue with Google"
- Authorize the application
- You should be redirected back to the dashboard
3. Multi-App Authentication Flow
Test authentication from another app (e.g., local-test):
-
Update local-test app to use auth-client:
cd apps/webs/local-test pnpm add @workspace/auth-client -
Create auth configuration in local-test:
// apps/webs/local-test/lib/auth.ts import { AuthClient } from "@workspace/auth-client" export const authClient = new AuthClient({ authUrl: process.env.NEXT_PUBLIC_AUTH_URL || "http://localhost:3030", appId: "local-test", redirectPath: "/dashboard", }) -
Add middleware to protect routes:
// apps/webs/local-test/middleware.ts import { NextResponse } from "next/server" import type { NextRequest } from "next/server" export function middleware(request: NextRequest) { const token = request.cookies.get("auth_token_local-test") if (!token && request.nextUrl.pathname.startsWith("/dashboard")) { const authUrl = new URL("http://localhost:3030") authUrl.searchParams.set("app", "local-test") authUrl.searchParams.set("return", request.url) return NextResponse.redirect(authUrl) } return NextResponse.next() } export const config = { matcher: ["/dashboard/:path*"], } -
Test the flow:
- Start local-test app:
pnpm dev --filter=local-test - Navigate to
http://localhost:3025/dashboard - You should be redirected to auth service
- After authentication, you'll be redirected back to local-test
- Start local-test app:
4. Session Validation
Test the session validation API:
# Get a session token first by signing in
# Then test validation
curl -X POST http://localhost:3030/api/session/validate \
-H "Content-Type: application/json" \
-d '{"token": "YOUR_SESSION_TOKEN"}'5. Session Refresh
Test token refresh:
curl -X POST http://localhost:3030/api/session/refresh \
-H "Content-Type: application/json" \
-d '{"refreshToken": "YOUR_REFRESH_TOKEN"}'Debugging
Check Convex Logs
Monitor the auth Convex deployment logs:
- Go to the Convex dashboard
- Select the auth deployment (dependable-pika-747)
- Check the Logs tab for any errors
Common Issues
-
"RESEND_API_KEY is not set"
- Add the Resend API key to Convex environment variables
-
OAuth redirect errors
- Verify OAuth callback URLs match exactly
- Check OAuth app configuration in GitHub/Google
-
Session not persisting
- Check browser cookies for auth tokens
- Verify cookie domain settings
-
CORS errors
- The auth service has CORS headers configured
- Ensure you're using the correct URLs
Testing Checklist
- Email OTP sign-in works
- OAuth sign-in works (if configured)
- Dashboard shows user info correctly
- Session validation API returns correct data
- Token refresh works properly
- Multi-app redirect flow works
- Sessions are created in Convex
- Audit logs are recorded
Production Deployment
-
Deploy Convex functions:
pnpm convex:auth:deploy -
Deploy to Vercel:
cd apps/webs/auth vercel --prod -
Update DNS:
- Point
auth.do.devto Vercel deployment
- Point
-
Update OAuth providers:
- Add production callback URLs
- Update environment variables
Integration with Other Apps
To integrate the auth service with other apps in the monorepo:
- Add
@workspace/auth-clientdependency - Configure the auth client with correct URLs
- Implement middleware for protected routes
- Use
authClient.validateSession()for API routes - Handle token storage and refresh
See the auth-client package README for detailed integration instructions.