A comprehensive expertise skill for Twenty CRM OAuth integration, troubleshooting, and best practices based on extensive session analysis.
Primary File: /home/agent/fratres/custom-skills/twenty-oauth-mastery.skill.md
Draft Documentation: /home/agent/fratres/.sisyphus/drafts/twenty-oauth-mastery-skill.md
Name: twenty-oauth-mastery
Expertise Level: Expert/Mastery
Applicable To:
- Twenty CRM authentication
- Google/Microsoft OAuth
- Token refresh management
- Domain restrictions
- Email/Calendar sync integration
File Structure: twenty/packages/twenty-server/src/engine/core-modules/auth/
auth/
├── strategies/ # Passport strategies (Google, Microsoft)
├── controllers/ # OAuth endpoints and callbacks
├── services/ # Auth logic, sync setup, token management
├── guards/ # Auth guards and validation
└── utils/ # Scope configuration, utilities
| Issue | Quick Fix |
|---|---|
| Redirect Loop | Rebuild: npx nx build twenty-server |
| .co Domain Blocked | Add to allowlist in 3 places |
| Sync Not Starting | Return tokens in validate() method |
| Cookie Not Readable | Set httpOnly: false |
| Infinite Loop | Track processed token signatures |
Passport Strategy (MUST FOLLOW):
passReqToCallback: true, // Required
return { ..., accessToken, refreshToken }; // Must preserve tokensToken Refresh:
// Preserve original refresh token (Google may not return new one)
return { accessToken: token, refreshToken: refreshToken };- Unit testing for token refresh
- Playwright for cookie injection testing
- Database verification for sync issues
Before Deploy:
- TypeScript source updated
- Tests passing
- Build completed
- Verify compiled JavaScript
After Deploy:
- Test OAuth flow manually
- Check browser console
- Verify redirect to dashboard
- Check database for connected accounts
6-step systematic approach:
- Verify container running new code
- Check Google Cloud Console
- Check environment variables
- Test OAuth entry point
- Check database (sync issues)
- Check logs
- Consult Quick Reference Table for immediate symptom-to-fix mapping
- Read Relevant Issue Section for detailed root cause analysis
- Follow Troubleshooting Workflow step-by-step
- Verify with Testing Strategies before deploying
- Review Architecture Knowledge to understand code structure
- Follow Critical Code Patterns for consistency
- Use Testing Strategies to ensure reliability
- Follow Deployment Checklist for deployment
- Identify symptom from Common Issues section
- Check file locations specified for your issue
- Apply recommended fixes in order
- Verify with database queries (if sync-related)
- Test with OAuth flow before considering complete
This skill compiles knowledge from 8 sessions spanning December 2025 - February 2026:
| Session | Focus | Key Learnings |
|---|---|---|
ses_3cbfedbc1ffe3jSWb8qlglnis4 |
Frontend token fix | Backend source not compiled, cookie attributes |
ses_3df1d0a33ffeylAsT2AYJY3ywW |
Enrichment testing | Container networking, environment variables |
ses_3e5fad76dffeMjB0CuX1p9QgfY |
OAuth 500 error RCA | Endpoint validation, error handling |
ses_3c19f4278ffeiqxcjgYJ7dy6tn |
OAuth codebase exploration | Comprehensive file analysis |
| Plan | Focus | Key Insights |
|---|---|---|
oauth-frontend-token-fix.md |
Cookie processing | Frontend token reading, infinite loops |
oauth-jnguyen-rca-plan.md |
Domain enforcement | .co domain blocking, allowlist strategy |
oauth-sync-integration.md |
Automatic sync | Token capture, channel creation, scope expansion |
oauth-redirect-domain-fix.md |
Redirect logic | isSingleDomainMode, cookie domain |
twenty-oauth-billing-fix.md |
OAuth billing | Billing feature gating, redirect URLs |
- Source-Compiled Code Mismatch: Backend fixes in TypeScript source but not in compiled JavaScript running in container
- Domain Restriction Pitfalls: Hardcoded domains blocking legitimate users with .co TLD
- Token Loss in Validation: Missing accessToken/refreshToken in validate() return object breaks automatic sync
- Cookie Attribute Errors:
httpOnly: trueprevents frontend from reading tokenPair cookie - Infinite Processing Loops: Same token signature processed repeatedly causing API spam
Each issue includes:
- Symptom description
- Root cause analysis
- File locations to check
- Step-by-step fixes
- Verification methods
# Build
npx nx build twenty-server # Backend
npx nx build twenty-front # Frontend
npx nx typecheck twenty-server # Type check
# Deployment
docker restart fratres-twenty # Restart container
# Verification
curl -f https://yourdomain.com/healthz # Health check
curl -v https://yourdomain.com/auth/google # Test OAuth
# Debugging
docker logs fratres-twenty --tail 100 # View logs
docker exec fratres-twenty env | grep AUTH_GOOGLE # Check env vars- Load skill when working on OAuth-related tasks
- Reference relevant sections based on your issue
- Follow the systematic troubleshooting workflow
- Apply critical code patterns for consistency
- Add new issues discovered during debugging
- Update code patterns as Twenty CRM evolves
- Additional testing strategies as you discover them
- New deployment insights from production updates
This skill represents expert-level OAuth knowledge distilled from extensive real-world debugging sessions. It provides:
- Immediate fixes for 5+ common OAuth issues
- Systematic workflows for troubleshooting
- Battle-tested code patterns for consistency
- Production-ready deployment checklist
- Database verification queries for sync issues
Use this skill whenever working with Twenty CRM OAuth to avoid common pitfalls and solve issues efficiently.
Created: 2026-02-08
Based On: 8 sessions, 5 plans, extensive codebase exploration
Maintained: /home/agent/fratres/custom-skills/twenty-oauth-mastery.skill.md