crosscode: scripts/products/website.sh (ports 5300/3300, uploads in the export), crosscode add <church> website (needs Accounts; www.<address> or the Cross Code address), one install_app for Accounts and the Website, env template copy, bats tests. Backend: Hub client (protocol v2, product website), crosscode.link/1 with automatic connect to the church's Accounts, sign-in through @crosscode/auth-client with the Website's own session and roles, the first Owner from HUB_ADMIN_EMAIL (verified), 2FA for Owners and Admins, back-channel logout, Accounts' user.* calls, and the church export. Frontend: admin sign-in/out and the sign-in problem page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { cookies } from "next/headers";
|
|
|
|
/** The signed-in admin (from the backend's /api/auth/me), for the admin's server-rendered pages. */
|
|
export type Me = {
|
|
user: { id: string; name: string; email: string; role: "owner" | "admin" | "editor" | "ministry_leader" | "viewer"; ministryId: string | null };
|
|
mfa: boolean;
|
|
};
|
|
|
|
const api = (process.env.WEBSITE_API_URL || "http://127.0.0.1:5300").replace(/\/+$/, "");
|
|
|
|
export const ROLE_NAMES: Record<Me["user"]["role"], string> = {
|
|
owner: "Owner",
|
|
admin: "Admin",
|
|
editor: "Editor",
|
|
ministry_leader: "Ministry leader",
|
|
viewer: "Viewer",
|
|
};
|
|
|
|
/** Null when signed out (or the backend can't say); the page then sends people to sign in. */
|
|
export async function loadMe(): Promise<Me | null> {
|
|
const session = (await cookies()).get("ccw_session")?.value;
|
|
if (!session) return null;
|
|
try {
|
|
const res = await fetch(`${api}/api/auth/me`, { headers: { Cookie: `ccw_session=${encodeURIComponent(session)}` }, cache: "no-store" });
|
|
if (res.ok) return (await res.json()) as Me;
|
|
} catch {
|
|
// The backend is starting or down: treated as signed out.
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/** Where "Sign in" goes for a page of the admin: Accounts, and back to that page. */
|
|
export const signInHref = (returnTo: string) => `/api/auth/signin?returnTo=${encodeURIComponent(returnTo)}`;
|