7.7 KiB
Authentication System - Testing Guide
Quick Start Testing
Prerequisites
- Django Backend Running
cd django-backend
python manage.py runserver
- Next.js Frontend Running
npm run dev
# or
bun dev
- Test User Account Create a test user via Django admin or API:
cd django-backend
python manage.py createsuperuser
Test Scenarios
Scenario 1: New User Registration
- Open http://localhost:3000
- Click "Sign Up" button
- Fill in the form:
- Username: testuser
- Email: test@example.com
- Password: TestPass123!
- Confirm Password: TestPass123!
- Click "Sign Up"
- Expected: Success message, modal closes
- Note: User needs to login separately (Django doesn't auto-login on registration)
Scenario 2: Login Flow
- Open http://localhost:3000
- Click "Login" button
- Enter credentials:
- Email: test@example.com
- Password: TestPass123!
- Click "Sign In"
- Expected:
- Modal closes
- User avatar appears in header
- Username/email displayed
- Dashboard link appears in welcome section
Scenario 3: Access Dashboard
- After logging in, click "Dashboard" link
- Expected:
- Redirected to /dashboard
- User profile card displays
- Username and email shown
- User ID visible
- Quick actions section present
Scenario 4: Logout Flow
- While logged in, click "Logout" button
- Expected:
- Redirected to home page
- Login/Sign Up buttons reappear
- Dashboard link hidden
- User avatar gone
Scenario 5: Protected Route Access
- Ensure you're logged out (click Logout if needed)
- Manually navigate to http://localhost:3000/dashboard
- Expected:
- Brief loading screen
- Automatic redirect to home page
Scenario 6: Token Persistence
- Login to the application
- Open browser DevTools → Application → Local Storage
- Expected:
thrillwiki_access_tokenpresentthrillwiki_refresh_tokenpresent
- Refresh the page (F5)
- Expected:
- User remains logged in
- No need to login again
Scenario 7: Password Reset Request
- Click "Login" button
- Click "Forgot your password?" link
- Enter email: test@example.com
- Click "Send Reset Email"
- Expected:
- Success message shown
- Check Django console for email output
- Email contains reset link
Scenario 8: OAuth Flow (Google)
Note: Requires Google OAuth configuration in Django backend
- Click "Login" button
- Click "Sign in with Google" button
- Expected:
- Redirected to Django OAuth endpoint
- Redirected to Google authorization
- After authorization, redirected back to callback
- Logged in and redirected to dashboard
Scenario 9: MFA Challenge
Note: Requires user with MFA enabled
- Enable MFA for test user in Django admin
- Login with that user
- Expected:
- After email/password, MFA code input appears
- Enter TOTP code from authenticator app
- After successful verification, redirected to dashboard
Scenario 10: Session Expiry
- Login to the application
- Open DevTools → Application → Local Storage
- Delete
thrillwiki_access_token - Try to navigate to dashboard
- Expected:
- Redirected to home page
- Need to login again
Browser DevTools Checks
Local Storage Verification
Open DevTools → Application → Local Storage → http://localhost:3000
When Logged In:
thrillwiki_access_token: eyJ0eXAiOiJKV1QiLCJhbGc...
thrillwiki_refresh_token: eyJ0eXAiOiJKV1QiLCJhbGc...
When Logged Out: Should be empty or missing
Network Requests
Open DevTools → Network → XHR
On Login:
- POST to
/api/v1/auth/login/ - Response:
{ "access": "...", "refresh": "..." } - GET to
/api/v1/auth/user/ - Response: User object with id, username, email
On Dashboard Load:
- GET to
/api/v1/auth/user/ - Should include
Authorization: Bearer <token>header
Error Scenarios to Test
Invalid Credentials
- Try to login with wrong password
- Expected: Error message "Invalid credentials" or similar
Network Error
- Stop Django backend
- Try to login
- Expected: Error message about network/server error
Token Expiry (Manual)
- Login successfully
- In DevTools, edit
thrillwiki_access_tokento invalid value - Try to access protected route
- Expected: Token refresh attempted, then logout if refresh fails
Validation Errors
- Try to register with:
- Password too short
- Passwords don't match
- Invalid email format
- Expected: Validation error messages displayed
Console Messages
Expected Console Output (Normal Flow)
Access token refreshed successfully // Every ~55 minutes
Auth check complete
User loaded: {username: "testuser", ...}
Error Console Output
Failed to refresh token: ...
Refresh token expired, logging out
Login failed: ...
API Endpoint Testing (Optional)
Using curl or Postman
Register:
curl -X POST http://localhost:8000/api/v1/auth/register/ \
-H "Content-Type: application/json" \
-d '{"username":"testuser","email":"test@example.com","password":"TestPass123!"}'
Login:
curl -X POST http://localhost:8000/api/v1/auth/login/ \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"TestPass123!"}'
Get User (with token):
curl http://localhost:8000/api/v1/auth/user/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Common Issues & Solutions
Issue: Can't login, getting 401 errors
Solution: Check Django backend is running and accessible at http://localhost:8000
Issue: CORS errors in console
Solution: Ensure Django settings have proper CORS configuration for http://localhost:3000
Issue: Tokens not persisting
Solution: Check browser privacy settings allow localStorage
Issue: OAuth not working
Solution: Verify OAuth credentials configured in Django backend .env file
Issue: MFA not appearing
Solution: User must have MFA enabled in Django admin first
Success Indicators
✅ All tests passing if:
- Can register new user
- Can login with valid credentials
- Dashboard loads with user info
- Logout works and clears session
- Protected routes redirect when not logged in
- Tokens persist across page refreshes
- Password reset email sent
- OAuth flow completes (if configured)
- MFA challenge works (if configured)
- Error messages display appropriately
Next Steps After Testing
- Fix any bugs found during testing
- Document any issues in GitHub issues
- Consider security audit before production
- Set up production environment variables
- Test in production-like environment (staging)
- Add automated tests (unit, integration, e2e)
- Monitor error logs for auth failures
- Set up user analytics (optional)
Testing Checklist
Use this checklist to track testing progress:
- New user registration works
- Login with email/password works
- Dashboard displays user info correctly
- Logout works and clears tokens
- Protected route redirects when logged out
- Direct dashboard access requires login
- Tokens persist on page refresh
- Password reset email sent
- OAuth Google works (if configured)
- OAuth Discord works (if configured)
- MFA challenge works (if configured)
- Invalid credentials show error
- Network errors handled gracefully
- Form validation works
- Token refresh works automatically
- Session expiry handled properly
- UI responsive on mobile
- Loading states display correctly
- Error messages clear and helpful
- No console errors (except expected ones)
Date Tested: ___________ Tested By: ___________ Environment: Development / Staging / Production Status: Pass / Fail / Needs Work