Files
t5de-hub/apps/web/app/console/actions.ts
T
dhkatzandClaude Opus 5.5 64c552330b Website: Next.js app for accounts, linking, who's online, device sign-in and the console
apps/web: Next.js 16 (App Router), Tailwind 4 and shadcn/ui, light and dark from the system. Pages render on the
server and call the API with Eden Treaty (typed by @t5de/api), forwarding the visitor's cookie; forms use server
actions; sign-up, sign-in and sign-out use Better Auth's React client. /api is rewritten to the API so its cookies
are first-party. Who's online follows the API's event stream (Next's gzip is off: it held the stream back).
Standalone output with a Dockerfile; deploys to Vercel as is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 05:02:00 -07:00

46 lines
1.8 KiB
TypeScript

"use server";
import { revalidatePath } from "next/cache";
import { api, unwrap } from "@/lib/api";
import { attempt, field, type ActionState } from "@/lib/actions";
const roles = ["user", "moderator", "admin"] as const;
/** Runs a change to a person from the console, then shows their page again. */
async function onPerson(form: FormData, change: (id: string) => Promise<string | void>): Promise<ActionState> {
const id = field(form, "id");
return attempt(async () => {
const notice = await change(id);
revalidatePath(`/console/people/${id}`);
return notice;
});
}
export async function setLinkCap(_: ActionState, form: FormData): Promise<ActionState> {
return onPerson(form, async (id) => {
const linkCap = Number(field(form, "linkCap"));
const { person } = unwrap(await api.console.people({ id })["link-cap"].post({ linkCap }));
return `Link cap set to ${person.linkCap}.`;
});
}
export async function ban(_: ActionState, form: FormData): Promise<ActionState> {
return onPerson(form, async (id) => {
unwrap(await api.console.people({ id }).ban.post({ reason: field(form, "reason") }));
});
}
export async function unban(_: ActionState, form: FormData): Promise<ActionState> {
return onPerson(form, async (id) => {
unwrap(await api.console.people({ id }).unban.post());
});
}
export async function setRole(_: ActionState, form: FormData): Promise<ActionState> {
return onPerson(form, async (id) => {
const role = roles.find((r) => r === field(form, "role")) ?? "user";
// The API's schema builds its union from an array, which its type reads as never; the value is checked above.
const { person } = unwrap(await api.console.people({ id }).role.post({ role: role as never }));
return `Role set to ${person.role}.`;
});
}