MCPcopy Create free account
hub / github.com/MemTensor/MemOS / handleLogin

Method handleLogin

packages/memos-core/src/viewer/server.ts:455–475  ·  view source on GitHub ↗
(req: http.IncomingMessage, res: http.ServerResponse)

Source from the content-addressed store, hash-verified

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 ?? "";

Callers 1

handleRequestMethod · 0.95

Calls 5

readBodyMethod · 0.95
hashPasswordMethod · 0.95
createSessionMethod · 0.95
endMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected