AI Engineering Workspace
PartialChat, files, terminal and preview in one place. Chat sessions run on a durable Postgres-backed queue (chat only: no tools or shell). Live models need an API key; the terminal is unavailable.
Project files
read-only- ..
- assets
- basic-languages
- editor
- language
- nls
- abap-D-t0cyap.js
- apex-CcIm7xu6.js
- azcli-BA0tQDCg.js
- bat-C397hTD6.js
- bicep-DF5aW17k.js
- cameligo-plsz8qhj.js
- clojure-Y2auQMzK.js
- coffee-Bu45yuWE.js
- cpp-CkKPQIni.js
- csharp-CX28MZyh.js
- csp-D8uWnyxW.js
- css-CaeNmE3S.js
- css.worker-C7XcYe5x.js
- cssMode-DpEkhVlW.js
- cypher-DVThT8BS.js
- dart-CmGfCvrO.js
- dockerfile-CZqqYdch.js
- ecl-30fUercY.js
- editor-CG9c2pE-.js
- editor.js
- elixir-O3PRlgxO.js
- flow9-DqtmStfK.js
- freemarker2-DTUDMAl2.js
- fsharp-BOMdg4U1.js
- go-D_hbi-Jt.js
- graphql-CKUU4kLG.js
- handlebars-qLqoXa-4.js
- hcl-DTaboeZW.js
- html-DTxBj26n.js
- html.worker-VIR_LTyv.js
- htmlMode-DFBg6CMj.js
- index-BVflv2uG.js
- index.js
- ini--YXggpAu.js
- java-CI4ZMsH9.js
- javascript-BiL3JN6i.js
- json.worker-DzWXGkG8.js
- jsonMode-Dz4r0pwo.js
- julia-BwzEvaQw.js
- kotlin-IUYPiTV8.js
- less-C0eDYdqa.js
- lexon-iON-Kj97.js
- liquid-lXEUQRVn.js
- loader.js
- lspLanguageFeatures-IeRAvoKK.js
- lua-DtygF91M.js
- m3-CsR4AuFi.js
- markdown-C_rD0bIw.js
- mdx-Dtr248s4.js
- mips-CiYP61RB.js
- monaco.contribution-BRs4bdz5.js
- monaco.contribution-ChoOM5Gg.js
- monaco.contribution-DbKqsbmO.js
- monaco.contribution-DKFaWvum.js
- msdax-C38-sJlp.js
- mysql-CdtbpvbG.js
- nls.messages-loader.js
- objective-c-CntZFaHX.js
- pascal-r6kuqfl_.js
- pascaligo-BiXoTmXh.js
- perl-DABw_TcH.js
- pgsql-me_jFXeX.js
- php-D_kh-9LK.js
- pla-VfZjczW0.js
- postiats-BBSzz8Pk.js
- powerquery-Dt-g_2cc.js
- powershell-B-7ap1zc.js
- protobuf-BmtuEB1A.js
- pug-BRpRNeEb.js
- python-Cma5OvNe.js
- qsharp-BzsFaUU9.js
- r-f8dDdrp4.js
- razor-C8pOqqry.js
- redis-fvZQY4PI.js
- redshift-45Et0LQi.js
- restructuredtext-C7UUFKFD.js
- ruby-CZO8zYTz.js
- rust-Bfetafyc.js
- sb-3GYllVck.js
- scala-foMgrKo1.js
- scheme-CHdMtr7p.js
- scss-C1cmLt9V.js
- shell-ClXCKCEW.js
- solidity-MZ6ExpPy.js
- sophia-DWkuSsPQ.js
- sparql-AUGFYSyk.js
- sql-32GpJSV2.js
- st-CuDFIVZ_.js
- swift-t-PfMj7W.js
- systemverilog-Ch4vA8Yt.js
- tcl-D74tq1nH.js
- toggleHighContrast-CmI6H2gJ.js
- ts.worker-Dp2_QI6H.js
- tsMode-DgC3tGu_.js
- twig-C6taOxMV.js
- typescript-PjDChiYw.js
- typespec-D-PIh9Xw.js
- vb-Dyb2648j.js
- wgsl-BhLXMOR0.js
- workers-B_Zs9c54.js
- xml-BgCkTIhY.js
- yaml-D0tu26m-.js
app/src/app/api/auth/login/route.ts
1import crypto from "node:crypto";2import { checkToken, createSession, isSecure, loginAllowed, sameOrigin, tokenConfigured } from "@/lib/auth";3import { audit } from "@/lib/audit";4import { asSystem, db } from "@/lib/db";5import { customerOpsEnabled, GATE_MSG, hashToken } from "@/lib/tenant";6import { userAdmitted } from "@/lib/gates";7import { trustedConnection } from "@/lib/tlsgate";8import { afterFailure, burn, hashPassword, policyError, verifyPassword, verifyTotp } from "@/lib/pwauth-core.mjs";9export const dynamic = "force-dynamic";10// The platform owner signs in with the admin token; customers with a personal access token issued by an org admin / super admin.11// Dev-only stopgap until Zoo IAM (OIDC). Customer sign-in additionally requires trusted HTTPS (or the explicit dev override).12export const POST = (req: Request) => asSystem(() => handle(req)); // identity is not known yet: explicit system scope for this bootstrap exchange13async function handle(req: Request) {14 if (!(await isSecure())) return Response.json({ error: "sign-in requires HTTPS" }, { status: 403 });15 if (!(await sameOrigin())) return Response.json({ error: "cross-origin rejected" }, { status: 403 });16 if (!loginAllowed()) return Response.json({ error: "too many attempts; wait a minute" }, { status: 429 });17 const body0 = await req.clone().json().catch(() => ({}));18 if (typeof body0.email === "string") return passwordLogin(body0);19 if (!tokenConfigured()) return Response.json({ error: "access token not provisioned on server" }, { status: 503 });20 const body = await req.json().catch(() => ({})); const token = String(body.token ?? "");21 if (checkToken(token)) { await createSession("usr_owner"); await audit("owner@platform.local", "auth.login", "usr_owner", { org: "org_owner" }); return Response.json({ ok: true }); }22 const u = token.length >= 20 ? await db().prepare("SELECT id,email,status,platform_admin FROM users WHERE token_hash=?").get(hashToken(token)) as any : null;23 if (!u || u.status !== "active") { await audit("anonymous", "auth.login.failed"); return Response.json({ error: "invalid token" }, { status: 401 }); }24 if (!u.platform_admin && (!(await customerOpsEnabled()).on || !(await userAdmitted(u.id)))) return Response.json({ error: GATE_MSG }, { status: 403 });25 await createSession(u.id); await audit(u.email, "auth.login", u.id); return Response.json({ ok: true });26}2728// E-mail + password. Credentials are only accepted over TRUSTED TLS (or the explicit, audited dev override); a temporary password must be changed in the same request.29async function passwordLogin(b: any) {30 const tc = await trustedConnection();31 if (!tc.ok) return Response.json({ error: "Password sign-in is only available over verified trusted HTTPS on the canonical host (" + tc.reason + ")." }, { status: 403 });32 const email = String(b.email ?? "").trim().toLowerCase(), pw = String(b.password ?? "");33 const bad = () => Response.json({ error: "invalid e-mail or password" }, { status: 401 });34 if (!email || !pw || pw.length > 128) { burn(pw); return bad(); }35 const u = await db().prepare("SELECT u.id,u.email,u.status,u.platform_admin,c.pw_hash,c.must_change,c.failed,c.locked_until,c.mfa_secret,c.mfa_enabled FROM users u JOIN user_credentials c ON c.user_id=u.id WHERE lower(u.email)=?").get(email) as any;36 if (!u || u.status !== "active" || !u.pw_hash) { burn(pw); await audit("anonymous", "auth.login.failed"); return bad(); }37 if (!u.platform_admin && (!(await customerOpsEnabled()).on || !(await userAdmitted(u.id)))) { burn(pw); return bad(); } // customers stay behind the customer-operations gate38 if (Number(u.locked_until) > Date.now()) { burn(pw); await audit(u.email, "auth.login.locked", u.id); return Response.json({ error: "account temporarily locked; try again later" }, { status: 429 }); }39 if (!verifyPassword(pw, u.pw_hash)) { const n = afterFailure(u.failed); await db().prepare("UPDATE user_credentials SET failed=?, locked_until=? WHERE user_id=?").run(n.failed, n.lockedUntil, u.id); await audit(u.email, n.lockedUntil ? "auth.login.lockout" : "auth.login.failed", u.id); return bad(); }40 if (u.mfa_enabled) { if (!b.totp) return Response.json({ error: "authentication code required", mfaRequired: true }, { status: 401 }); if (!verifyTotp(u.mfa_secret, b.totp)) { await audit(u.email, "auth.login.failed", u.id); return bad(); } }41 if (u.must_change) {42 if (!b.newPassword) return Response.json({ error: "password change required", mustChange: true }, { status: 428 }); // no session is created43 const pe = policyError(String(b.newPassword), { email: u.email, old: pw }); if (pe) return Response.json({ error: pe, mustChange: true }, { status: 422 });44 await db().prepare("UPDATE user_credentials SET pw_hash=?, must_change=0, failed=0, locked_until=0, changed_at=? WHERE user_id=?").run(hashPassword(String(b.newPassword)), new Date().toISOString(), u.id); // the temporary credential is now void45 await db().prepare("DELETE FROM sessions WHERE user_id=?").run(u.id); await audit(u.email, "auth.password.changed", u.id);46 } else await db().prepare("UPDATE user_credentials SET failed=0, locked_until=0 WHERE user_id=?").run(u.id);47 await createSession(u.id); await audit(u.email, "auth.login", u.id, { method: "password" }); return Response.json({ ok: true });48}49
Conversation
PartialSign in to start AI sessions.
Task checklist
- Application shell deployed
- Persistent projects
- Agent runtime
- Sandboxed terminal
Execution activity
No agent sessions. Git HEAD 692573d on master.
Approval requests
None pending.