Skip to content
Merged

51 #64

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
14 changes: 0 additions & 14 deletions .gemini/settings.json

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ dist/
coverage/
comandos.txt
debug/
.gemini/

12 changes: 8 additions & 4 deletions src/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@ import { Request, Response, NextFunction } from 'express';
import { config } from '#config/index';
import { logger } from '#core/logger';

export const authenticate = (req: Request, res: Response, next: NextFunction) => {

export const authenticate = (req: Request, res: Response, next: NextFunction): void => {
const authHeader = req.headers['authorization'];

if (!authHeader) {
logger.warn('Authentication failed: No Authorization header');
return res.status(401).json({ error: 'Authorization header required' });
res.status(401).json({ error: 'Authorization header required' });
return;
}

const tokenParts = authHeader.split(' ');

if (tokenParts.length !== 2 || tokenParts[0].toLowerCase() !== 'bearer') {
logger.warn('Authentication failed: Invalid token format');
return res.status(401).json({ error: 'Invalid token format. Expected "Bearer <token>"' });
res.status(401).json({ error: 'Invalid token format. Expected "Bearer <token>"' });
return;
}

const token = tokenParts[1];

if (token !== config.apiKey) {
logger.warn('Authentication failed: Invalid API key');
return res.status(401).json({ error: 'Invalid API key' });
res.status(401).json({ error: 'Invalid API key' });
return;
}

logger.info('Authentication successful');
Expand Down