feat: establish ZITADEL OIDC account portal foundation

This commit is contained in:
Vib Tools committed 2026-11-22 04:25:33 -08:00
1 parent 4404849fc4
commit 40af500750
28 files changed
+898 -10

No files matched your search

@@ -0,0 +1,46 @@
import Link from "next/link";
import { AccountCard } from "@/components/account-card";
import { requireIdentity } from "@/lib/identity";
export const metadata = { title: "Account overview" };
export default async function AccountPage() {
const user = await requireIdentity();
const displayName = user.name?.trim() || user.email || "there";
return (
<div className="content-stack">
<div className="page-heading">
<p className="eyebrow">ACCOUNT OVERVIEW</p>
<h1>Welcome, {displayName}</h1>
<p className="muted">
Your identity is managed centrally. Each connected SaaS product
manages its own subscriptions, billing and application data.
</p>
</div>
<div className="overview-grid">
<AccountCard
title="Personal information"
description="Review the identity information supplied by your central account."
href="/account/profile"
action="View profile"
/>
<AccountCard
title="Password & security"
description="Open security settings, password and MFA controls in ZITADEL."
href="/account/security"
action="Security options"
/>
</div>
<section className="note-card" aria-labelledby="account-notice">
<h2 id="account-notice">One account. Multiple applications.</h2>
<p>
Your ZitPlane identity can be used with multiple connected apps.
Billing and product-specific permissions remain inside each app.
</p>
<Link className="text-link" href="/account/profile">Review account details</Link>
</section>
</div>
);
}
@@ -0,0 +1,47 @@
import { DataRow } from "@/components/account-card";
import { requireIdentity, zitadelSelfServiceUrl } from "@/lib/identity";
export const metadata = { title: "Personal information" };
export default async function ProfilePage() {
const user = await requireIdentity();
return (
<div className="content-stack">
<div className="page-heading">
<p className="eyebrow">PROFILE</p>
<h1>Personal information</h1>
<p className="muted">
These details come from your authenticated ZITADEL session.
They are read-only in this foundation release.
</p>
</div>
<section className="card" aria-labelledby="profile-details">
<div className="card-header">
<h2 id="profile-details">Account details</h2>
<span className="pill">Central identity</span>
</div>
<dl className="data-list">
<DataRow label="Display name" value={user.name} />
<DataRow label="Email address" value={user.email} />
<DataRow label="ZITADEL User ID" value={user.id} />
</dl>
<p className="form-note">
The immutable identity ID links your account across applications.
Email addresses can change; do not use them as an account database key.
</p>
</section>
<section className="note-card">
<h2>Need to update your information?</h2>
<p>
Use your ZITADEL self-service settings if your organization allows
account editing there. This portal does not currently modify identity data.
</p>
<a className="button button-outline" href={zitadelSelfServiceUrl()}>
Open ZITADEL account settings
<span aria-hidden="true"> ↗</span>
</a>
</section>
</div>
);
}
@@ -0,0 +1,58 @@
import { requireIdentity, zitadelSelfServiceUrl } from "@/lib/identity";
export const metadata = { title: "Security" };
const items = [
{
title: "Password",
detail: "Password changes and recovery are handled by ZITADEL."
},
{
title: "Multi-factor authentication",
detail: "Manage available authenticators and verification methods under your identity policies."
},
{
title: "Passkeys and security keys",
detail: "Available methods depend on your organization's ZITADEL configuration."
}
];
export default async function SecurityPage() {
await requireIdentity();
return (
<div className="content-stack">
<div className="page-heading">
<p className="eyebrow">SECURITY</p>
<h1>Security settings</h1>
<p className="muted">
ZitPlane delegates credentials and authentication to ZITADEL.
No password or MFA secret is stored in this portal.
</p>
</div>
<section className="card" aria-labelledby="security-tools">
<h2 id="security-tools">Account protection</h2>
<div className="setting-list">
{items.map((item) => (
<div className="setting-row" key={item.title}>
<div>
<h3>{item.title}</h3>
<p className="muted">{item.detail}</p>
</div>
<span className="pill">ZITADEL</span>
</div>
))}
</div>
<a className="button button-primary" href={zitadelSelfServiceUrl()}>
Open central security settings
<span aria-hidden="true"> ↗</span>
</a>
</section>
<p className="form-note">
This link opens the existing ZITADEL self-service console. Access and
available controls depend on the user's permissions and active policies.
Portal-local sign-out does not terminate every application's SSO session.
</p>
</div>
);
}
+15
View File
@@ -0,0 +1,15 @@
import type { ReactNode } from "react";
import { AccountShell } from "@/components/account-shell";
import { requireIdentity } from "@/lib/identity";
export const dynamic = "force-dynamic";
export default async function ProtectedLayout({
children
}: {
children: ReactNode;
}) {
const user = await requireIdentity();
return <AccountShell user={user}>{children}</AccountShell>;
}
+26
View File
@@ -0,0 +1,26 @@
import { NextResponse } from "next/server";
import { auth } from "@/auth";
export const dynamic = "force-dynamic";
export async function GET() {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json(
{ error: "Unauthorized" },
{ status: 401, headers: { "Cache-Control": "private, no-store" } }
);
}
return NextResponse.json(
{
user: {
id: session.user.id,
name: session.user.name ?? null,
email: session.user.email ?? null
}
},
{ headers: { "Cache-Control": "private, no-store" } }
);
}
@@ -0,0 +1,3 @@
import { handlers } from "@/auth";
export const { GET, POST } = handlers;
+21
View File
@@ -0,0 +1,21 @@
import type { Metadata } from "next";
import type { ReactNode } from "react";
import "@/styles/globals.css";
export const metadata: Metadata = {
title: {
default: "ZitPlane Account",
template: "%s | ZitPlane"
},
description: "Centralized account and security settings for your ZitPlane identity.",
robots: { index: false, follow: false }
};
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
+5
View File
@@ -0,0 +1,5 @@
import { redirect } from "next/navigation";
export default function Home() {
redirect("/account");
}
+42
View File
@@ -0,0 +1,42 @@
import Link from "next/link";
import { redirect } from "next/navigation";
import { auth, signIn } from "@/auth";
export const dynamic = "force-dynamic";
export default async function SignInPage() {
const session = await auth();
if (session?.user?.id) {
redirect("/account");
}
async function startLogin() {
"use server";
await signIn("zitadel", { redirectTo: "/account" });
}
return (
<main className="sign-in-screen">
<section className="sign-in-card" aria-labelledby="signin-title">
<div className="brand-symbol" aria-hidden="true">Z</div>
<p className="eyebrow">ZITPLANE IDENTITY</p>
<h1 id="signin-title">Your account, one secure place.</h1>
<p className="muted">
Sign in with your central ZITADEL identity to manage your account.
Passwords, passkeys, and MFA stay with your identity provider.
</p>
<form action={startLogin}>
<button className="button button-primary button-full" type="submit">
Continue with ZITADEL
</button>
</form>
<p className="fine-print">
New to ZitPlane? Registration is handled by the central sign-in service,
according to its account policies.
</p>
<Link className="text-link" href="/">Back to account home</Link>
</section>
</main>
);
}
+69
View File
@@ -0,0 +1,69 @@
import NextAuth from "next-auth";
import Zitadel from "next-auth/providers/zitadel";
import { oidcSettings } from "@/lib/env";
/**
* The ZITADEL account portal is a standard OIDC relying party.
* No ZITADEL master key, service PAT or user password is used here.
* Auth.js manages PKCE, state, callbacks and encrypted HTTP-only session cookies.
*
* The local app session expires no later than the initial OIDC access-token lifetime.
* Automatic refresh and federated logout are deliberately future-scoped work.
*/
export const { handlers, auth, signIn, signOut } = NextAuth(() => {
const { issuer, clientId, clientSecret, secret, trustHost } = oidcSettings();
return {
secret,
trustHost,
providers: [
Zitadel({
issuer,
clientId,
clientSecret,
checks: ["pkce", "state", "nonce"],
authorization: { params: { scope: "openid profile email" } }
})
],
session: { strategy: "jwt", maxAge: 60 * 60 },
callbacks: {
async signIn({ account, profile }) {
return (
account?.provider === "zitadel" &&
typeof profile?.sub === "string" &&
profile.sub.length > 0
);
},
async jwt({ token, account }) {
if (account?.provider === "zitadel") {
token.zitadelSubject =
typeof account.providerAccountId === "string"
? account.providerAccountId
: undefined;
// Fail closed when the provider does not return an expiration.
token.zitadelTokenExpiresAt =
typeof account.expires_at === "number" ? account.expires_at : 0;
}
return token;
},
async session({ session, token }) {
const valid =
typeof token.zitadelSubject === "string" &&
token.zitadelSubject.length > 0 &&
typeof token.zitadelTokenExpiresAt === "number" &&
token.zitadelTokenExpiresAt * 1000 > Date.now();
// Never expose an authenticated identity when an OIDC token has expired.
// Every page and API checks nonempty user.id; do not gate on !!session alone.
return {
...session,
user: {
...session.user,
id: valid ? token.zitadelSubject! : ""
}
};
}
}
};
});
+37
View File
@@ -0,0 +1,37 @@
import Link from "next/link";
import type { ReactNode } from "react";
export function AccountCard({
title,
description,
href,
action
}: {
title: string;
description: ReactNode;
href: string;
action: string;
}) {
return (
<article className="card action-card">
<h2>{title}</h2>
<p className="muted">{description}</p>
<Link className="button button-outline" href={href}>{action}</Link>
</article>
);
}
export function DataRow({
label,
value
}: {
label: string;
value?: string | null;
}) {
return (
<div className="data-row">
<dt>{label}</dt>
<dd>{value || "Not provided"}</dd>
</div>
);
}
+80
View File
@@ -0,0 +1,80 @@
import Link from "next/link";
import type { ReactNode } from "react";
import { signOut } from "@/auth";
type AccountUser = {
id: string;
name?: string | null;
email?: string | null;
image?: string | null;
};
const navigation = [
{ href: "/account", label: "Overview", description: "Account home" },
{ href: "/account/profile", label: "Profile", description: "Personal information" },
{ href: "/account/security", label: "Security", description: "Credentials and access" }
] as const;
export function AccountShell({
user,
children
}: {
user: AccountUser;
children: ReactNode;
}) {
async function portalLogout() {
"use server";
await signOut({ redirectTo: "/signin" });
}
return (
<div className="app-layout">
<aside className="sidebar">
<Link href="/account" className="brand" aria-label="ZitPlane account home">
<span className="brand-symbol" aria-hidden="true">Z</span>
<span className="brand-label">
<strong>ZitPlane</strong>
<small>Account Center</small>
</span>
</Link>
<p className="nav-heading">ACCOUNT</p>
<nav aria-label="Account navigation" className="nav-list">
{navigation.map((item) => (
<Link key={item.href} href={item.href} className="nav-item">
<span>{item.label}</span>
<small>{item.description}</small>
</Link>
))}
</nav>
<div className="sidebar-spacer" />
<div className="identity-tile">
<div className="avatar" aria-hidden="true">
{(user.name ?? user.email ?? "U").charAt(0).toUpperCase()}
</div>
<div className="identity-text">
<strong>{user.name || "Account user"}</strong>
<small>{user.email || "Signed in with ZITADEL"}</small>
</div>
</div>
<form action={portalLogout}>
<button type="submit" className="button button-subtle button-full">
Sign out of portal
</button>
</form>
</aside>
<div className="main-column">
<header className="topbar">
<span className="topbar-label">Identity &amp; security</span>
<span className="status-dot"><span aria-hidden="true" /> Signed in</span>
</header>
<main id="main-content" className="main-content">
{children}
</main>
<footer className="footer">
ZitPlane Account Center · Authentication powered by ZITADEL
</footer>
</div>
</div>
);
}
+46
View File
@@ -0,0 +1,46 @@
import "server-only";
function required(name: string): string {
const value = process.env[name]?.trim();
if (!value || value.startsWith("REPLACE_")) {
throw new Error(`Missing required account portal setting: ${name}`);
}
return value;
}
function validatedUrl(name: string): string {
const raw = required(name);
const url = new URL(raw);
const loopback = url.hostname === "localhost" || url.hostname === "127.0.0.1";
if (
!["http:", "https:"].includes(url.protocol) ||
(url.protocol !== "https:" && (process.env.NODE_ENV === "production" || !loopback)) ||
url.username ||
url.password ||
url.search ||
url.hash ||
url.pathname !== "/"
) {
throw new Error(`${name} must be an HTTPS origin (HTTP localhost only in development)`);
}
return url.origin;
}
export function oidcSettings() {
const secret = required("AUTH_SECRET");
if (secret.length < 32) {
throw new Error("AUTH_SECRET must be at least 32 characters");
}
const issuer = validatedUrl("ZITADEL_ISSUER");
validatedUrl("AUTH_URL");
const clientId = required("ZITADEL_CLIENT_ID");
const clientSecret = required("ZITADEL_CLIENT_SECRET");
return {
issuer,
clientId,
clientSecret,
secret,
trustHost: process.env.AUTH_TRUST_HOST === "true"
};
}
+24
View File
@@ -0,0 +1,24 @@
import "server-only";
import { redirect } from "next/navigation";
import { auth } from "@/auth";
export async function requireIdentity() {
const session = await auth();
if (!session?.user?.id) {
redirect("/signin");
}
return session.user;
}
/** Browser-facing ZITADEL settings link, not an administrative API endpoint. */
export function zitadelSelfServiceUrl(): string {
const issuer = process.env.ZITADEL_ISSUER;
if (!issuer) {
throw new Error("Missing ZITADEL_ISSUER");
}
// Validate via a well-defined URL; never accept browser-supplied redirect targets.
const origin = new URL(issuer).origin;
return new URL("/ui/console/users/me", origin).toString();
}
+135
View File
@@ -0,0 +1,135 @@
:root {
color-scheme: light dark;
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
--bg: #f6f7f9;
--panel: #ffffff;
--panel-subtle: #f9fafb;
--ink: #1c2633;
--muted: #627187;
--line: #e4e9f0;
--accent: #235bdb;
--accent-hover: #194ab5;
--accent-soft: #eaf0ff;
--success: #078060;
--shadow: 0 5px 24px rgba(21, 36, 58, 0.04);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.55; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
a:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.65rem, 4vw, 2.05rem); line-height: 1.22; letter-spacing: -.035em; }
h2 { font-size: 1rem; line-height: 1.3; }
h3 { font-size: .9rem; }
p { margin-bottom: 1rem; }
.muted { color: var(--muted); }
.eyebrow { font-size: .68rem; letter-spacing: .14em; color: var(--accent); font-weight: 750; margin-bottom: .8rem; }
.app-layout { min-height: 100dvh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 15px; padding: 25px 18px 20px; background: var(--panel); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-symbol { display: grid; place-items: center; background: var(--accent); color: #fff; width: 39px; height: 39px; border-radius: 12px; font-weight: 800; font-size: 1.2rem; letter-spacing: -.06em; flex: none; }
.brand-label { display: flex; flex-direction: column; line-height: 1.25; }
.brand-label strong { font-size: 1rem; letter-spacing: -.02em; }
.brand-label small { margin-top: 4px; color: var(--muted); font-size: .73rem; }
.nav-heading { font-size: .66rem; letter-spacing: .12em; color: var(--muted); font-weight: 700; margin: 24px 10px 0; }
.nav-list { display: grid; gap: 5px; }
.nav-item { padding: 10px 12px; border-radius: 9px; display: flex; flex-direction: column; gap: 1px; font-weight: 650; }
.nav-item small { font-size: .73rem; font-weight: 400; color: var(--muted); }
.nav-item:hover, .nav-item:focus-visible { background: var(--accent-soft); }
.sidebar-spacer { flex: 1; }
.identity-tile { display: flex; align-items: center; gap: 9px; padding: 10px; background: var(--panel-subtle); border: 1px solid var(--line); border-radius: 11px; }
.avatar { width: 33px; height: 33px; display: grid; place-items: center; border-radius: 50%; color: var(--accent); background: var(--accent-soft); font-weight: 750; flex: none; }
.identity-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.4; }
.identity-text strong, .identity-text small { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.identity-text strong { font-size: .78rem; }
.identity-text small { font-size: .7rem; color: var(--muted); }
.main-column { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 63px; padding: 0 clamp(22px, 4vw, 52px); border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar-label { color: var(--muted); font-size: .8rem; font-weight: 600; }
.status-dot { display: inline-flex; align-items: center; gap: 8px; font-size: .74rem; color: var(--muted); }
.status-dot > span { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.main-content { width: 100%; max-width: 1130px; margin: 0 auto; padding: 38px clamp(22px, 4vw, 52px) 70px; flex: 1; }
.content-stack { display: grid; gap: 24px; }
.page-heading { max-width: 690px; }
.page-heading h1 { margin-bottom: 12px; }
.page-heading .muted { margin-bottom: 0; max-width: 630px; }
.overview-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 25px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { margin-bottom: 9px; }
.card .muted { font-size: .85rem; }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-bottom: 10px; }
.action-card { display: flex; flex-direction: column; align-items: flex-start; min-height: 182px; }
.action-card .muted { flex: 1; }
.note-card { background: var(--panel-subtle); border: 1px solid var(--line); border-radius: 14px; padding: 23px 25px; }
.note-card p { color: var(--muted); font-size: .86rem; max-width: 680px; }
.note-card h2 { margin-bottom: 8px; }
.pill { border-radius: 99px; background: var(--accent-soft); padding: 5px 10px; color: var(--accent); white-space: nowrap; font-size: .67rem; font-weight: 650; }
.button { display: inline-flex; gap: 8px; justify-content: center; align-items: center; text-align: center; min-height: 37px; padding: 8px 14px; border-radius: 9px; border: 1px solid transparent; font-weight: 650; font-size: .81rem; transition: background .15s ease, border-color .15s ease; }
.button-primary { color: #fff; background: var(--accent); }
.button-primary:hover { background: var(--accent-hover); }
.button-outline { background: var(--panel); border-color: var(--line); }
.button-outline:hover { background: var(--panel-subtle); border-color: var(--accent); }
.button-subtle { color: var(--ink); background: transparent; border-color: var(--line); }
.button-subtle:hover { background: var(--panel-subtle); }
.button-full { width: 100%; }
.text-link { color: var(--accent); font-weight: 650; font-size: .83rem; }
.text-link:hover { text-decoration: underline; }
.footer { text-align: center; color: var(--muted); font-size: .72rem; padding: 18px; border-top: 1px solid var(--line); }
.data-list { margin: 0; }
.data-row { display: grid; grid-template-columns: minmax(140px, 28%) 1fr; gap: 20px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.data-row:last-child { border-bottom: none; }
.data-row dt { color: var(--muted); }
.data-row dd { margin: 0; overflow-wrap: anywhere; font-weight: 570; }
.form-note, .fine-print { font-size: .76rem; color: var(--muted); line-height: 1.7; }
.setting-list { margin-bottom: 24px; }
.setting-row { display: flex; gap: 15px; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--line); padding: 15px 0; }
.setting-row:last-child { border-bottom: none; }
.setting-row h3 { margin-bottom: 4px; }
.setting-row p { margin: 0; max-width: 520px; }
.sign-in-screen { min-height: 100dvh; display: flex; justify-content: center; align-items: center; padding: 28px; }
.sign-in-card { width: 100%; max-width: 430px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); padding: 35px; box-shadow: var(--shadow); }
.sign-in-card .brand-symbol { margin-bottom: 26px; }
.sign-in-card h1 { font-size: 1.8rem; margin-bottom: 16px; }
.sign-in-card .muted { margin-bottom: 28px; }
.sign-in-card .fine-print { margin: 16px 0 20px; }
@media (max-width: 760px) {
.app-layout { display: flex; flex-direction: column; }
.sidebar { position: static; height: auto; gap: 12px; padding: 14px 18px; border-right: none; border-bottom: 1px solid var(--line); }
.brand { padding: 0; }
.nav-heading, .sidebar-spacer, .identity-tile { display: none; }
.nav-list { display: flex; gap: 5px; overflow-x: auto; }
.nav-item { white-space: nowrap; padding: 7px 10px; }
.nav-item small { display: none; }
.sidebar form { align-self: flex-start; }
.topbar { min-height: 48px; padding: 0 18px; }
.main-content { padding: 26px 18px 48px; }
.overview-grid { grid-template-columns: 1fr; }
.card, .note-card { padding: 19px; }
.data-row { grid-template-columns: 1fr; gap: 3px; }
.sign-in-card { padding: 27px; }
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #10151d;
--panel: #171f2a;
--panel-subtle: #1c2633;
--ink: #eef3fa;
--muted: #a7b5c8;
--line: #2e3a4a;
--accent: #78a6ff;
--accent-hover: #5b8bea;
--accent-soft: #263951;
--success: #33b999;
--shadow: 0 4px 24px rgba(0, 0, 0, .08);
}
.button-primary { background: #346aca; color: #fff; }
.button-primary:hover { background: #2756b2; }
.brand-symbol { background: #346aca; }
}
+16
View File
@@ -0,0 +1,16 @@
import type { DefaultSession } from "next-auth";
declare module "next-auth" {
interface Session {
user: DefaultSession["user"] & {
id: string;
};
}
}
declare module "next-auth/jwt" {
interface JWT {
zitadelSubject?: string;
zitadelTokenExpiresAt?: number;
}
}