(req: http.IncomingMessage, res: http.ServerResponse)
| 453 | } |
| 454 | |
| 455 | private handleLogin(req: http.IncomingMessage, res: http.ServerResponse): void { |
| 456 | this.readBody(req, (body) => { |
| 457 | try { |
| 458 | const { password } = JSON.parse(body); |
| 459 | if (this.needsSetup || this.hashPassword(password) !== this.auth.passwordHash) { |
| 460 | res.writeHead(401, { "Content-Type": "application/json" }); |
| 461 | res.end(JSON.stringify({ error: "Invalid password" })); |
| 462 | return; |
| 463 | } |
| 464 | const token = this.createSession(); |
| 465 | res.writeHead(200, { |
| 466 | "Content-Type": "application/json", |
| 467 | "Set-Cookie": `${this.cookieName}=${token}; Path=/; HttpOnly; SameSite=Strict; Max-Age=86400`, |
| 468 | }); |
| 469 | res.end(JSON.stringify({ ok: true })); |
| 470 | } catch (err) { |
| 471 | res.writeHead(401, { "Content-Type": "application/json" }); |
| 472 | res.end(JSON.stringify({ error: String(err) })); |
| 473 | } |
| 474 | }); |
| 475 | } |
| 476 | |
| 477 | private handleLogout(req: http.IncomingMessage, res: http.ServerResponse): void { |
| 478 | const cookie = req.headers.cookie ?? ""; |
no test coverage detected