(event: H3Event)
| 53 | }) |
| 54 | |
| 55 | function requireAuth(event: H3Event): void { |
| 56 | const authHeader = event.req.headers.get('authorization') |
| 57 | if (!authHeader || !authHeader.startsWith('Bearer ')) { |
| 58 | throw new HTTPError({ statusCode: 401, message: 'Authorization required' }) |
| 59 | } |
| 60 | const token = authHeader.slice(7) |
| 61 | if (token !== stateManager.token) { |
| 62 | throw new HTTPError({ statusCode: 401, message: 'Invalid token' }) |
| 63 | } |
| 64 | if (!stateManager.isConnected()) { |
| 65 | throw new HTTPError({ statusCode: 401, message: 'Not connected' }) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // POST /connect |
| 70 | app.post('/connect', async (event: H3Event) => { |
no test coverage detected