• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apowers313 / aiforge / 20962792399

13 Jan 2026 03:39PM UTC coverage: 84.707%. First build
20962792399

push

github

apowers313
feat: initial commit

787 of 905 branches covered (86.96%)

Branch coverage included in aggregate %.

4248 of 5039 new or added lines in 70 files covered. (84.3%)

4248 of 5039 relevant lines covered (84.3%)

13.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.26
/src/server/api/middleware/auth.ts
1
/**
2
 * Authentication middleware for API routes
3
 */
4
import type { Request, Response, NextFunction, RequestHandler } from 'express';
5
import type { AuthService } from '../../services/auth/AuthService.js';
6

7
// Extend Express Request to include auth service
8
declare module 'express-serve-static-core' {
9
  interface Request {
10
    authService?: AuthService;
11
    isAuthenticated?: boolean;
12
  }
13
}
14

15
/**
16
 * Middleware to attach auth service to request
17
 */
18
export function attachAuthService(authService: AuthService): RequestHandler {
1✔
19
  return (req: Request, _res: Response, next: NextFunction): void => {
8✔
20
    req.authService = authService;
116✔
21
    next();
116✔
22
  };
116✔
23
}
8✔
24

25
/**
26
 * Middleware to require authentication
27
 * Checks for session cookie and validates it
28
 */
29
export function requireAuth(req: Request, res: Response, next: NextFunction): void {
1✔
30
  const cookies = req.cookies as { session?: string };
92✔
31
  const sessionToken = cookies.session;
92✔
32

33
  if (!sessionToken) {
92✔
34
    res.status(401).json({ error: 'Authentication required' });
7✔
35
    return;
7✔
36
  }
7✔
37

38
  if (!req.authService) {
92!
NEW
39
    res.status(500).json({ error: 'Auth service not configured' });
×
NEW
40
    return;
×
NEW
41
  }
✔
42

43
  req.authService.validateSession(sessionToken)
85✔
44
    .then((valid) => {
85✔
45
      if (!valid) {
85!
NEW
46
        res.status(401).json({ error: 'Invalid or expired session' });
×
NEW
47
        return;
×
NEW
48
      }
×
49
      req.isAuthenticated = true;
85✔
50
      next();
85✔
51
    })
85✔
52
    .catch(() => {
85✔
NEW
53
      res.status(500).json({ error: 'Authentication error' });
×
54
    });
85✔
55
}
85✔
56

57
/**
58
 * Middleware to check auth status without requiring it
59
 * Sets req.isAuthenticated to true or false
60
 */
61
export function checkAuth(req: Request, _res: Response, next: NextFunction): void {
1✔
62
  const cookies = req.cookies as { session?: string };
22✔
63
  const sessionToken = cookies.session;
22✔
64

65
  if (!sessionToken || !req.authService) {
22✔
66
    req.isAuthenticated = false;
1✔
67
    next();
1✔
68
    return;
1✔
69
  }
1✔
70

71
  req.authService.validateSession(sessionToken)
21✔
72
    .then((valid) => {
21✔
73
      req.isAuthenticated = valid;
21✔
74
      next();
21✔
75
    })
21✔
76
    .catch(() => {
21✔
NEW
77
      req.isAuthenticated = false;
×
NEW
78
      next();
×
79
    });
21✔
80
}
21✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc