Files
crosscode-platform/apps/accounts/backend/src/public/routes.ts
T
joshuaandClaude Opus 5.5 f202a5a88e 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>
2026-11-18 13:42:45 +02:00

58 lines
2.1 KiB
TypeScript

/**
* Public endpoints: the church's branding for the sign-in pages, the church profile for its
* products (`GET /api/church/v1`, contracts 1.5.0), and Connect (`/api/links/v1/*`, as Events 2.4).
*/
import express, { type Response } from 'express';
import { CHURCH_PATHS, LINK_PATHS, LINK_SCHEMA } from '@crosscode/contracts';
import type { Ctx } from '../context.js';
import { handle, limit } from '../http.js';
import { branding, church } from '../church/profile.js';
import { acceptConnect, acceptDisconnect, LinkError } from '../links/connect.js';
import { setupNeeded } from '../setup/routes.js';
import { currentNotice } from '../privacy/notice.js';
const strip = (p: string) => p.replace(/^\/api/, '');
function linkError(res: Response, e: unknown) {
if (e instanceof LinkError) return res.status(e.status).json({ message: e.message, code: e.code });
console.error('[links]', e);
return res.status(500).json({ message: 'Something went wrong.', code: 'SERVER_ERROR' });
}
export function publicRouter(ctx: Ctx) {
const r = express.Router();
const json = express.json({ limit: '16kb' });
r.get('/v2/branding', handle(async () => ({ ...(await branding(ctx)), setupNeeded: await setupNeeded(ctx) })));
// The privacy notice, for the sign-up page's link (public).
r.get('/v2/notice', handle(async () => {
const n = await currentNotice(ctx);
return { version: n.version, title: n.title, body: n.body, publishedAt: n.publishedAt };
}));
r.get(strip(CHURCH_PATHS.profile), limit(600), handle(async (_req, res) => {
res.set('Cache-Control', 'public, max-age=60');
return church(ctx);
}));
r.post(strip(LINK_PATHS.connect), limit(30), json, async (req, res) => {
try {
res.json(await acceptConnect(ctx, req.body, req));
} catch (e) {
linkError(res, e);
}
});
r.post(strip(LINK_PATHS.disconnect), limit(30), json, async (req, res) => {
try {
await acceptDisconnect(ctx, req.body, req);
res.json({ schema: LINK_SCHEMA, type: 'link.disconnected' });
} catch (e) {
linkError(res, e);
}
});
return r;
}