Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

1.8 KB
Raw Blame
import { z } from "zod";
import { audit, revokeAllAdminTokens } from "@/server/admin-tokens";
import { authEnabled, SESSION_COOKIE, sessionCookieOf, signOutEveryone, validSession } from "@/server/auth";
import { revokeAllWorkers } from "@/server/computer/pool";

/**
 * Settings → Security → Sign everyone out: a new session secret, so every signed-in browser (the owner's, this one
 * too, and every account's) has to sign in again. It works while FUOBE_PASSWORD is set. Only from the owner's
 * signed-in browser (an API token can't do it). With { tokens: true }, every API token is revoked too, admin tokens
 * included, and every worker's token (their jobs go back in line; people's own paired ComfyUIs stay paired).
 */
export async function POST(request: Request) {
  if (!authEnabled()) return Response.json({ error: "Set a password first. Without one, nobody signs in." }, { status: 400 });
  if (!validSession(sessionCookieOf(request))) return Response.json({ error: "Sign everyone out from the owner's signed-in browser" }, { status: 403 });
  const parsed = z.object({ tokens: z.boolean().optional() }).safeParse(await request.json().catch(() => ({})));
  const tokensRevoked = parsed.success && parsed.data.tokens === true;
  signOutEveryone({ tokens: tokensRevoked });
  if (tokensRevoked) {
    const n = revokeAllAdminTokens();
    if (n) audit({ kind: "owner" }, "token.revoke_all", null, { count: n }, 200);
    const workers = revokeAllWorkers();
    if (workers) audit({ kind: "owner" }, "worker.revoke_all", null, { count: workers }, 200);
  }
  const secure = new URL(request.url).protocol === "https:" ? "; Secure" : "";
  return Response.json(
    { ok: true, tokensRevoked },
    { headers: { "Set-Cookie": `${SESSION_COOKIE}=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax${secure}`, "Cache-Control": "no-store" } },
  );
}