- Issue:
createUserIfNotExistsfunction was imported but didn't exist - Fix: Added the missing function to
src/server/implementations/user.impl.ts
- Issue: No error handling or logging in authentication flow
- Fix: Added console logs throughout the authentication chain:
- JWT callback (
src/server/auth/callbacks/jwt.callback.ts) - User service (
src/server/services/user.service.ts) - User mapper (
src/server/auth/mappers/user.mapper.ts) - Firebase implementation (
src/server/implementations/user.impl.ts) - Firebase admin initialization (
src/server/utils/firebase-admin.ts)
- JWT callback (
Make sure these environment variables are set in your .env.local file:
# GitHub OAuth
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
# NextAuth
NEXTAUTH_SECRET=your_nextauth_secret
NEXTAUTH_URL=http://localhost:3000
# Firebase
FIREBASE_SERVICE_ACCOUNT_KEY={"type":"service_account","project_id":"your_project_id",...}node test-firebase.js# Verify these are set
echo $GITHUB_CLIENT_ID
echo $GITHUB_CLIENT_SECRET
echo $NEXTAUTH_SECRET
echo $FIREBASE_SERVICE_ACCOUNT_KEY- Start your development server:
npm run dev - Open browser developer tools (F12)
- Go to Console tab
- Try signing in with GitHub
- Look for the console logs we added
When signing in with GitHub, you should see logs like:
Firebase service account loaded successfully
Firebase Admin initialized successfully
Firestore database instance created
JWT Callback triggered
User: [GitHub Username]
Account provider: github
Profile: [GitHub Username]
Processing user and account data
fetchOrCreateUser called
mapToCreateUserDTO called
Account provider: github
Mapped GitHub info: { id: "123", username: "username", ... }
Looking for user with username: [username]
User not found: [username]
Creating new user: [username]
Successfully created user: [username]
User data successfully fetched/created: [username]
Token updated with user data
- Problem: Invalid or malformed service account key
- Solution: Download fresh service account key from Firebase Console
- Problem: Incorrect client ID/secret or callback URL
- Solution: Verify GitHub OAuth app settings in GitHub Developer Settings
- Problem: Missing or incorrect NEXTAUTH_SECRET
- Solution: Generate a secure random string for NEXTAUTH_SECRET
- Problem: Cross-origin requests blocked
- Solution: Ensure NEXTAUTH_URL matches your development URL
- Run the Firebase test script
- Check all environment variables are set
- Try signing in and monitor console logs
- If issues persist, check the specific error messages in the logs
src/server/implementations/user.impl.ts- Added missing function and loggingsrc/server/auth/callbacks/jwt.callback.ts- Added error handling and loggingsrc/server/services/user.service.ts- Added comprehensive loggingsrc/server/auth/mappers/user.mapper.ts- Added debugging logssrc/server/utils/firebase-admin.ts- Added validation and error handlingtest-firebase.js- Created Firebase connection testDEBUG_CHECKLIST.md- This debugging guide