ATProto User Creation & Sync Investigation Summary#
Date: October 14, 2025
Status: 🔴 CRITICAL ISSUES FOUND
🔍 Investigation Overview#
Investigated the user creation flow from Auth0 signup → MongoDB → ATProto PDS to understand why ATProto accounts are not being automatically created.
📋 Current Flow (Expected)#
- User Signs Up → Auth0
- Auth0 Log Stream → Webhook to
/.netlify/functions/auth0-events(event type: "ss") - auth0-events.mjs:
- ✅ Creates
verificationsrecord (count: 0) - ✅ Creates
usersrecord with generated code
- ✅ Creates
- User Verifies Email → Auth0
- Auth0 Log Stream → Webhook to
/.netlify/functions/auth0-events(event type: "sv") - auth0-events.mjs:
- ✅ Increments
verificationscount to 1 - ✅ Calls
createAtprotoAccount()to create PDS account - ✅ Stores ATProto credentials in
userscollection
- ✅ Increments
🐛 Issues Found#
Issue #1: Users Records Not Created ❌#
Affected Users: All 5 recent signups (100%)
Evidence:
MongoDB Collections Status:
Verifications: 5/5 ✅ (100%)
Users: 0/5 ❌ (0%)
Handles: 3/5 (60%)
ATProto: 0/5 ❌ (0%)
Root Cause:
The user code generation in auth0-events.mjs is failing silently:
try {
await ensureUserCodeIndex(database);
const signupDate = new Date(log.data.date);
const code = await generateUniqueUserCode(database, signupDate);
const users = database.db.collection("users");
await users.insertOne({
_id: aestheticSub,
code,
when: signupDate
});
shell.log("🎫 Generated user code:", code, "for:", aestheticSub);
} catch (error) {
shell.log("⚠️ Failed to generate user code:", aestheticSub, error);
// Don't block signup on code generation failure
}
The error is logged but swallowed, so signup succeeds but user record is never created.
Impact:
- No user codes generated
- No ATProto accounts created (dependent on user records)
- Users can still sign up and use handles, but missing identity data
Issue #2: ATProto Accounts Not Created ❌#
Affected Users: All 4 email-verified users (100%)
Root Cause: Cascading failure from Issue #1
createAtprotoAccount()requires user record to exist- Without user record, no code is available for fallback handle
- ATProto account creation is never attempted
Evidence from auth0-events.mjs:
// 🦋 Create ATProto account on first verification
shell.log("🦋 Creating ATProto account for newly verified user...");
const atprotoResult = await createAtprotoAccount(
database,
aestheticSub,
);
This code runs, but likely fails because:
- No user record with code exists
- User may not have handle set yet
createAtprotoAccount()needs either handle or code
✅ What's Working#
-
Auth0 Log Stream Webhook - Confirmed working
AUTH0_LOG_TOKENis set in Netlify env- Signup events ("ss") are being received
- Verification events ("sv") are being received
-
Verifications Collection - Working perfectly
- All users have verification records
- Counts are accurate (0 for unverified, 1 for verified)
-
Handles Collection - Partially working
- 3 out of 5 users have handles set
- Handle creation via
/handle.mjsendpoint works
🔧 Recommended Fixes#
Fix #1: Investigate User Code Generation Failure#
Priority: 🔴 CRITICAL
Action Items:
- Check Netlify function logs for user code generation errors
- Review
generateUniqueUserCode()implementation - Check if MongoDB index creation is failing
- Verify database permissions for inserting into
userscollection
Command to check logs:
netlify functions:log auth0-events
Fix #2: Backfill Missing User Records#
Priority: 🟡 HIGH
Action:
cd /workspaces/aesthetic-computer/at
node scripts/test-user-creation-flow.mjs 5 --fix
This will:
- Create missing
usersrecords with generated codes - Create ATProto accounts for email-verified users
- Sync all data to PDS
Affected Users:
auth0|68ee503033f18c5d54238469- Needs user record (email not verified)auth0|68ee500f0729405b6c0dfa18- Needs user record + ATProto accountauth0|68ee4fe6041a48c2971c7fb1- Needs user record + ATProto accountauth0|68ede47abdf0b654d1475476- Needs user record + ATProto accountauth0|68ebc6c78aa676dc64c40609- Needs user record + ATProto account
Fix #3: Improve Error Handling#
Priority: 🟢 MEDIUM
Update auth0-events.mjs to:
- Log full error details (not just message)
- Send alerts for user creation failures
- Retry user code generation
- Create user record with temporary/fallback code if generation fails
📊 Detailed Audit Results#
Recent Users Status (Last 5 Signups)#
User 1: auth0|68ee503033f18c5d54238469#
- Email: bjarke.hee@gmail.com
- Email Verified: ❌
- Created: 6.1 hours ago
- Verifications: ✅ (count=0)
- Users Record: ❌
- Handle: None
- ATProto: ❌
User 2: auth0|68ee500f0729405b6c0dfa18#
- Email: csx0909@gmail.com
- Email Verified: ✅
- Created: 6.1 hours ago
- Verifications: ✅ (count=1)
- Users Record: ❌
- Handle: @csx
- ATProto: ❌
User 3: auth0|68ee4fe6041a48c2971c7fb1#
- Email: violinoletsgo@gmail.com
- Email Verified: ✅
- Created: 6.1 hours ago
- Verifications: ✅ (count=1)
- Users Record: ❌
- Handle: None
- ATProto: ❌
User 4: auth0|68ede47abdf0b654d1475476#
- Email: ligands-bays1k@icloud.com
- Email Verified: ✅
- Created: 13.7 hours ago
- Verifications: ✅ (count=1)
- Users Record: ❌
- Handle: @zhuxin
- ATProto: ❌
User 5: auth0|68ebc6c78aa676dc64c40609#
- Email: christianbluhme@yahoo.dk
- Email Verified: ✅
- Created: 52.3 hours ago (2.2 days)
- Verifications: ✅ (count=1)
- Users Record: ❌
- Handle: @43
- ATProto: ❌
📁 Files Involved#
Netlify Functions#
/system/netlify/functions/auth0-events.mjs- Webhook handler (ISSUE HERE)/system/netlify/functions/handle.mjs- Handle management
Backend#
/system/backend/at.mjs- ATProto account creation/system/backend/authorization.mjs- User lookup functions/system/backend/database.mjs- MongoDB connection/system/public/aesthetic.computer/lib/user-code.mjs- Code generation
Audit Scripts (Created)#
/at/scripts/audit-user-creation-sync.mjs- Full audit tool/at/scripts/test-user-creation-flow.mjs- Fix/backfill tool/at/scripts/check-auth0-webhook-config.mjs- Config checker
🎯 Next Steps#
- Immediate: Check Netlify logs for actual error messages
- Quick Fix: Run backfill script with
--fixflag - Root Cause: Debug why user code generation is failing
- Long-term: Add monitoring/alerting for user creation failures
- Testing: Create test users to verify fix
📞 Key Questions to Answer#
- ❓ What is the actual error message from user code generation?
- ❓ Is it a MongoDB permission issue?
- ❓ Is it a unique index collision issue?
- ❓ Has this been working in the past, or is it a new deployment issue?
- ❓ Are there any rate limits or throttling on MongoDB writes?
Investigation Tools Available:
audit-user-creation-sync.mjs- Check sync statustest-user-creation-flow.mjs- Simulate/fix user creationcheck-auth0-webhook-config.mjs- Verify webhook config