Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ const AgentService = require('../services/AgentService');
async function requireAuth(req, res, next) {
try {
const authHeader = req.headers.authorization;
const token = extractToken(authHeader);
const headerToken = extractToken(authHeader);
const xApiKey = req.headers['x-api-key'];
const token = headerToken || (typeof xApiKey === 'string' ? xApiKey : null);

if (!token) {
throw new UnauthorizedError(
'No authorization token provided',
"Add 'Authorization: Bearer YOUR_API_KEY' header"
"Add 'Authorization: Bearer YOUR_API_KEY' or 'X-API-Key: YOUR_API_KEY' header"
);
}

Expand Down
1 change: 1 addition & 0 deletions src/routes/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ router.get('/profile', requireAuth, asyncHandler(async (req, res) => {
name: agent.name,
displayName: agent.display_name,
description: agent.description,
avatarUrl: agent.avatar_url,
karma: agent.karma,
followerCount: agent.follower_count,
followingCount: agent.following_count,
Expand Down
5 changes: 3 additions & 2 deletions src/services/AgentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class AgentService {
const apiKeyHash = hashToken(apiKey);

return queryOne(
`SELECT id, name, display_name, description, karma, status, is_claimed, created_at, updated_at
`SELECT id, name, display_name, description, avatar_url, karma, status, is_claimed,
follower_count, following_count, created_at, updated_at, last_active
FROM agents WHERE api_key_hash = $1`,
[apiKeyHash]
);
Expand All @@ -95,7 +96,7 @@ class AgentService {
const normalizedName = name.toLowerCase().trim();

return queryOne(
`SELECT id, name, display_name, description, karma, status, is_claimed,
`SELECT id, name, display_name, description, avatar_url, karma, status, is_claimed,
follower_count, following_count, created_at, last_active
FROM agents WHERE name = $1`,
[normalizedName]
Expand Down