Accounts 1.0.0 frontend and @crosscode/ui

Sign-in steps (password, sign-up, email code, two-step sign-in and its
setup with recovery codes, privacy notice, news question), forgot and
reset password, the account page, admin (people, deletions, church
profile, linked products, settings, notice, licence, audit) and setup.
Strict CSP with a nonce per page; church colours from the profile.
@crosscode/ui gets its first components (shell, card, fields, buttons).
Plan: roles stay in each product (asked 2026-11-18).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 13:42:45 +02:00
co-authored by Claude Opus 5.5
parent a888260f01
commit f202a5a88e
36 changed files with 1521 additions and 5 deletions
+26
View File
@@ -0,0 +1,26 @@
/**
* Calls to the backend from the browser (same address, under /api). Errors come back as
* { error: { code, message, fields? } }; `call` returns them instead of throwing.
*/
export type ApiError = { code: string; message: string; fields?: Record<string, string> };
export type ApiResult<T> = { ok: true; status: number; data: T } | { ok: false; status: number; error: ApiError };
export async function call<T = Record<string, unknown>>(method: "GET" | "POST" | "PUT" | "DELETE", path: string, body?: unknown): Promise<ApiResult<T>> {
let res: Response;
try {
res = await fetch(`/api/v2${path}`, {
method,
credentials: "same-origin",
headers: body !== undefined ? { "Content-Type": "application/json" } : undefined,
body: body !== undefined ? JSON.stringify(body) : undefined,
});
} catch {
return { ok: false, status: 0, error: { code: "OFFLINE", message: "We couldn't reach the server. Check your connection and try again." } };
}
const json = (await res.json().catch(() => ({}))) as { error?: ApiError };
if (!res.ok) return { ok: false, status: res.status, error: json.error ?? { code: "ERROR", message: "Something went wrong. Please try again." } };
return { ok: true, status: res.status, data: json as T };
}
/** Where to sign in to Accounts' own pages, coming back to `returnTo`. */
export const selfSignIn = (returnTo: string, extra = "") => `/api/self/signin?returnTo=${encodeURIComponent(returnTo)}${extra}`;
@@ -0,0 +1,30 @@
/** The church's branding from the backend, for the server-rendered frame of every page. */
export type BrandingData = {
name: string;
shortName: string | null;
logoUrl: string | null;
colours: { primary: string; accent: string | null };
signupEnabled: boolean;
setupNeeded: boolean;
};
const api = (process.env.ACCOUNTS_API_URL || "http://127.0.0.1:5200").replace(/\/+$/, "");
export async function loadBranding(): Promise<BrandingData> {
try {
const res = await fetch(`${api}/api/v2/branding`, { cache: "no-store" });
if (res.ok) return (await res.json()) as BrandingData;
} catch {
// The backend is starting or down: plain defaults, the page still works.
}
return { name: "Sign in", shortName: null, logoUrl: null, colours: { primary: "#1f4e79", accent: null }, signupEnabled: true, setupNeeded: false };
}
/** "#1f4e79" → "31 78 121" (Tailwind's rgb(var(--brand) / alpha)), and a darker shade for hover. */
export function rgbVars(hex: string): { brand: string; dark: string } {
const m = /^#([0-9a-f]{6})$/i.exec(hex) ?? ["", "1f4e79"];
const n = parseInt(m[1]!, 16);
const [r, g, b] = [(n >> 16) & 255, (n >> 8) & 255, n & 255];
const d = (x: number) => Math.round(x * 0.8);
return { brand: `${r} ${g} ${b}`, dark: `${d(r)} ${d(g)} ${d(b)}` };
}
+14
View File
@@ -0,0 +1,14 @@
import { useEffect, type DependencyList } from "react";
/**
* `useEffect` for loading from the API and setting state from it (as Cross Events' lib/hooks.ts):
* the React Compiler lint can't tell that apart from state derived from other state.
*/
export function useExternalEffect(run: () => void | (() => void) | Promise<unknown>, deps: DependencyList) {
useEffect(() => {
const out = run();
return typeof out === "function" ? out : undefined;
// The caller's deps, checked at the call site by exhaustive-deps (additionalHooks).
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
}