(req: IncomingMessage, name: string)
| 11 | const SESSION_COOKIE = 'session=authenticated'; |
| 12 | |
| 13 | function getCookie(req: IncomingMessage, name: string): string | undefined { |
| 14 | const cookies = req.headers.cookie?.split(';').map(c => c.trim()) ?? []; |
| 15 | const cookie = cookies.find(c => c.startsWith(`${name}=`)); |
| 16 | return cookie?.split('=')[1]; |
| 17 | } |
| 18 | |
| 19 | function isAuthenticated(req: IncomingMessage): boolean { |
| 20 | return getCookie(req, 'session') === 'authenticated'; |