Backend Components:
- ✅
AuthService- Complete with all required methods - ✅
AuthController- All 7 endpoints implemented - ✅
JWT Strategy- Proper token validation - ✅
Password Utils- bcrypt hashing with security - ✅
Device Fingerprinting- Unique device identification - ✅
Token Utils- Secure token generation/validation - ✅ Database Entities - User, RefreshToken, Session, FailedLoginAttempt
Frontend Components:
- ✅
AuthContext- Centralized state management - ✅ Authentication Pages - Login, Register, Reset, Verify
- ✅
ProtectedRoute- Route security component - ✅ Session Management - Enhanced sessions page
- ✅ Navigation - Dynamic auth-aware header
# 1. Start Backend (NestJS)
cd backend
npm install
npm run start:dev
# Should start on http://localhost:3001
# 2. Start Frontend (Next.js)
cd ../
npm install
npm run dev
# Should start on http://localhost:3000- Navigate to
http://localhost:3000/register - Fill out the form with valid data
- ✅ Expected: Registration success message
- ✅ Expected: Email verification notice
- Navigate to
http://localhost:3000/login - Enter registered credentials
- ✅ Expected: Redirect to dashboard
- ✅ Expected: User name appears in header
- ✅ Expected: "Logout" button visible
- While logged in, visit
http://localhost:3000/dashboard - ✅ Expected: Dashboard loads with user info
- Open incognito window, try to access dashboard
- ✅ Expected: Redirect to login page
- Visit
http://localhost:3000/sessions - ✅ Expected: See current session listed
- Open another browser, log in again
- ✅ Expected: See multiple sessions
- Try to revoke a session
- ✅ Expected: Session removed from list
- Visit
http://localhost:3000/forgot-password - Enter email address
- ✅ Expected: Success message (even if email doesn't exist)
curl -X POST http://localhost:3001/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "SecurePass123!",
"firstName": "John",
"lastName": "Doe"
}'✅ Expected: User object without password field
curl -X POST http://localhost:3001/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "SecurePass123!"
}'✅ Expected:
{
"accessToken": "eyJ...",
"refreshToken": "abc123...",
"user": {
"id": "uuid",
"email": "test@example.com",
"firstName": "John",
"lastName": "Doe"
}
}curl -X POST http://localhost:3001/auth/refresh \
-H "Content-Type: application/json" \
-d '{
"refreshToken": "your_refresh_token_here"
}'✅ Expected: New access and refresh tokens
- Try logging in with wrong password 5 times
- ✅ Expected: Account locked message
- Wait 15 minutes or check database
- Login and get access token
- Wait 16 minutes (access token expires in 15)
- Make authenticated request
- ✅ Expected: 401 Unauthorized
- Use refresh token
- ✅ Expected: New access token
- Login from different browsers
- Check sessions page
- ✅ Expected: Different device entries
Connect to PostgreSQL and verify tables exist:
-- Check if tables were created
SELECT table_name FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name IN ('users', 'refresh_tokens', 'sessions', 'failed_login_attempts');
-- Check user creation
SELECT id, email, "firstName", "lastName", "emailVerified", "isActive"
FROM users LIMIT 5;
-- Check sessions
SELECT id, "userId", "deviceFingerprint", "ipAddress", "lastActivityAt"
FROM sessions;
-- Check refresh tokens
SELECT id, "userId", "expiresAt", "replacedBy"
FROM refresh_tokens;- Register with weak password ✅ Expected: Validation error
- Register with invalid email ✅ Expected: Validation error
- Login with non-existent user ✅ Expected: Invalid credentials
- Use expired token ✅ Expected: Token expired error
- Send invalid JSON ✅ Expected: 400 Bad Request
- Missing required fields ✅ Expected: Validation errors
- Invalid token format ✅ Expected: 401 Unauthorized
# Install wrk (on Mac: brew install wrk)
# Test login endpoint
wrk -t4 -c10 -d10s -s login-script.lua http://localhost:3001/auth/login- ✅ Forms have proper validation messages
- ✅ Loading states show during requests
- ✅ Success/error states display correctly
- ✅ Responsive design works on mobile
- ✅ Navigation updates based on auth state
- ✅ Registration → Verification notice → Login works
- ✅ Forgot password → Reset email → Password reset works
- ✅ Session management is intuitive
- ✅ Logout works and clears state
- ✅ Hot reload works with auth state
- ✅ Console shows helpful debug info
- ✅ Error boundaries catch auth errors
- ✅ Environment variables properly configured
- ✅ JWT secrets are secure (not default)
- ✅ CORS configured correctly
- ✅ Rate limiting in place
Register → Verify Email → Login → Use Protected Features →
Manage Sessions → Reset Password → Login Again → Logout
# Check if backend is running
curl http://localhost:3001/auth/login -I
# Check if frontend is running
curl http://localhost:3000 -I
# Test registration endpoint
curl -X POST http://localhost:3001/auth/register \
-H "Content-Type: application/json" \
-d '{"email":"test@test.com","password":"Test123!","firstName":"Test","lastName":"User"}'
# Check authentication state
curl -X POST http://localhost:3001/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"test@test.com","password":"Test123!"}'| Feature | Expected Behavior | Status |
|---|---|---|
| Registration | Creates user, sends verification email | ✅ |
| Login | Returns JWT tokens, redirects to dashboard | ✅ |
| Logout | Clears tokens, redirects to home | ✅ |
| Token Refresh | Auto-refreshes before expiry | ✅ |
| Password Reset | Sends reset email, allows password change | ✅ |
| Session Management | Shows all devices, allows revocation | ✅ |
| Account Lockout | Locks after 5 failed attempts | ✅ |
| Route Protection | Blocks unauthorized access | ✅ |
| Device Fingerprinting | Tracks unique devices | ✅ |
| Error Handling | Shows user-friendly messages | ✅ |
| Issue | Solution |
|---|---|
| "Cannot connect to database" | Start Docker services first |
| "JWT secret not configured" | Set environment variables |
| "CORS error" | Configure backend CORS settings |
| "Token expired" | Implement auto-refresh logic |
| "Registration not working" | Check email service configuration |
🎯 If all these tests pass, the authentication system is working correctly!