Skip to content

Conversation

@vreshch
Copy link
Contributor

@vreshch vreshch commented Nov 30, 2025

Problem

When publishing agents via CLI using device code authentication, users receive a User not found error (500 Internal Server Error).

Root Cause

The JWT auth middleware sets req.user.userId, but all agent routes were accessing req.user.id (which is only set during OAuth callback flows).

Solution

Updated all 9 agent route files to correctly access the user ID from both authentication methods:

// Support both JWT auth (userId) and OAuth callback (id/_id)
const userId = req.user?.userId || req.user?.id || req.user?._id?.toString();

Files Changed

  • Required auth routes (with proper validation):

    • publish.ts
    • delete.ts
    • update-metadata.ts
  • Optional auth routes:

    • get-agent.ts
    • search.ts
    • list.ts
    • versions.ts
    • get-version.ts
    • mcp-servers.ts

Testing

  • TypeScript compilation passes with no errors
  • Device code auth flow now correctly resolves the user ID

The JWT auth middleware sets req.user.userId, but agent routes were
accessing req.user.id (only set during OAuth callback). This caused
'User not found' errors when publishing agents via CLI/device code auth.

Updated all agent routes to support both authentication methods:
- req.user.userId (JWT/device code auth)
- req.user.id or req.user._id (OAuth callback auth)

Affected routes:
- publish.ts, delete.ts, update-metadata.ts (required auth)
- get-agent.ts, search.ts, list.ts, versions.ts, get-version.ts, mcp-servers.ts (optional auth)
@github-actions
Copy link

Pull Request Validation Successful

Step Results:

  • 📦 Install dependencies: true
  • 🔍 Run linting: true
  • 🧪 Run tests: true
  • 🏗️ Build packages: true

🎉 All quality checks passed! Ready to merge.

📋 View workflow run


🐳 Docker Images Built Successfully!

🏷️ Tag: pr-12

  • Backend: ✅ Built
  • Frontend: ✅ Built

📋 View workflow


⏰ Generated at: 2025-11-30T22:32:48.574Z

@vreshch vreshch merged commit 3f992a4 into master Nov 30, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants