feat: establish ZITADEL OIDC account portal foundation
This commit is contained in:
1 parent
4404849fc4
commit
40af500750
28 files changed
+898
-10
No files matched your search
@@ -0,0 +1,12 @@
|
||||
# ZitPlane Account Portal example ONLY (never store real values in Git).
|
||||
# Create local users/ui/.env.local or inject secrets from a secure host/CI secret store.
|
||||
# The issuer is the external, browser-reachable ZITADEL instance URL.
|
||||
ZITADEL_ISSUER=http://localhost:8080
|
||||
ZITADEL_CLIENT_ID=REPLACE_WITH_ACCOUNT_PORTAL_OIDC_CLIENT_ID
|
||||
# For Auth.js, use a confidential client and real secret.
|
||||
# Do NOT put the ZITADEL server master key or Login V2 PAT here.
|
||||
ZITADEL_CLIENT_SECRET=REPLACE_WITH_ACCOUNT_PORTAL_OIDC_CLIENT_SECRET
|
||||
AUTH_SECRET=REPLACE_WITH_RANDOM_AT_LEAST_32_CHARACTERS
|
||||
AUTH_URL=http://localhost:3001
|
||||
# Only enable when behind a trusted reverse proxy that sanitizes forwarded host headers.
|
||||
AUTH_TRUST_HOST=false
|
||||
@@ -0,0 +1,9 @@
|
||||
node_modules/
|
||||
.next/
|
||||
out/
|
||||
coverage/
|
||||
*.tsbuildinfo
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
*.log
|
||||
+76
-2
@@ -1,3 +1,77 @@
|
||||
# Account portal frontend
|
||||
# ZitPlane — Central Account Portal (P04)
|
||||
|
||||
Reserved for a separate responsive Next.js self-service UI. ZITADEL remains the source of authentication and identity. Phase 04 will introduce the application with secure user-scoped APIs; there is no runnable portal yet.
|
||||
**Status:** Source foundation implemented, **not built, tested, started or deployed**. The UI is compact and responsive, but its visual redesign is reserved for P06.
|
||||
|
||||
This is a separate Next.js 16 + React 19 App Router frontend using Auth.js / NextAuth.js 5.0.0-beta.32 and the built-in **ZITADEL OIDC provider**. No passwords, token-management UI, fake sessions or credentials are stored by this application. It does not replace the official ZITADEL Admin Console or the Login V2 frontend.
|
||||
|
||||
## Simple folder guide
|
||||
|
||||
| Folder | Change here for |
|
||||
| --- | --- |
|
||||
| `src/app/signin/` | Public sign-in entry (redirects to ZITADEL) |
|
||||
| `src/app/(protected)/account/` | Overview, read-only profile and security landing pages |
|
||||
| `src/components/` | Navigation shell, buttons and reusable display components |
|
||||
| `src/styles/globals.css` | Mobile, light/dark styling and design tokens |
|
||||
| `src/auth.ts` | **Protected** OIDC/auth configuration. Never edit for visual tasks |
|
||||
| `src/lib/env.ts` | **Protected** runtime configuration validation |
|
||||
| `src/lib/identity.ts` | **Protected** mandatory server-side identity checks |
|
||||
| `src/app/api/` | Auth.js OIDC callback route and a protected, read-only `/api/account/me` |
|
||||
| `src/types/` | Auth.js session type (immutable ZITADEL user ID) |
|
||||
|
||||
## Routes and what works in source
|
||||
|
||||
- `/` redirects to `/account`.
|
||||
- `/signin` offers **real Auth.js OIDC sign-in**, no mock login.
|
||||
- `/account` is server-side protected.
|
||||
- `/account/profile` displays OIDC name/email/immutable subject **read-only**.
|
||||
- `/account/security` explains credential ownership and links to ZITADEL self-service **if enabled for this user**. No local password/MFA editing is claimed.
|
||||
- `/api/account/me` returns the authenticated user's ID/name/email only, or 401; no-store, no privileged ZITADEL API.
|
||||
- `Sign out of portal` ends the local Auth.js session, **not necessarily global ZITADEL/other SaaS SSO**.
|
||||
- The portal **never** manages app billing, subscriptions, license keys or product permissions.
|
||||
|
||||
Access is checked in the protected layout **and individually in sensitive pages/API routes** using a nonempty verified session.user.id. Token expiry is tracked; if expiry is absent or past, the user ID is cleared (fail closed). Identity comes from the OIDC `sub`/providerAccountId, not mutable email. Refresh tokens, explicit global SSO logout, session revocation and account edit workflows are NOT implemented in P04.
|
||||
|
||||
## Future development settings (DOCUMENTATION ONLY)
|
||||
|
||||
Choose a dedicated **confidential ZITADEL Web/OIDC client**, authorization code + PKCE, with client secret held only on the account server. Do NOT reuse the official Login V2 service PAT, the ZITADEL master key, an arbitrary public client secret, or another SaaS app's client credentials.
|
||||
|
||||
In development, register the exact callback:
|
||||
|
||||
`http://localhost:3001/api/auth/callback/zitadel`
|
||||
|
||||
For production, register the exact callback:
|
||||
|
||||
`https://account.vib.tools/api/auth/callback/zitadel`
|
||||
|
||||
Enable HTTP redirect dev mode **only on disposable local ZITADEL**. The production OIDC issuer and `AUTH_URL` must be HTTPS.
|
||||
|
||||
Provide runtime variables (see `.env.example`):
|
||||
|
||||
| Variable | Purpose |
|
||||
| --- | --- |
|
||||
| `ZITADEL_ISSUER` | External, browser-accessible ZITADEL issuer URL, e.g. https://auth.vib.tools |
|
||||
| `ZITADEL_CLIENT_ID` | Dedicated Account Portal OIDC client ID |
|
||||
| `ZITADEL_CLIENT_SECRET` | Dedicated server-side confidential client secret |
|
||||
| `AUTH_SECRET` | Unique random secret, at least 32 characters |
|
||||
| `AUTH_URL` | Exact public Account Portal origin (no trailing path) |
|
||||
| `AUTH_TRUST_HOST` | `true` only behind a correctly configured, trusted reverse proxy |
|
||||
|
||||
Neither P02 Docker nor a production domain is wired to this portal in P04. An isolated Gitea CI phase will first need to create a **reviewed deterministic lockfile** (this phase did not install dependencies), install dependencies, validate Auth.js beta/Next.js compatibility, typecheck/build, perform security checks and test OIDC callbacks against disposable ZITADEL. **Until those gates pass, do not deploy or claim production readiness.**
|
||||
|
||||
## Source-only dependency notes
|
||||
|
||||
Pinned versions are declared in `package.json` without package-manager invocation. Auth.js 5.0.0-beta.32 is the patched version for GHSA-8fpg-xm3f-6cx3; both route protection and API access additionally require `session.user.id`, not just a truthy session. Future CI must review new security advisories and create a locked dependency graph. `npm ci` cannot work until the lockfile is created and approved.
|
||||
|
||||
## Security notes for AI UI editors
|
||||
|
||||
- Allowed visual edits in later P06: `src/components/**`, `src/styles/**` and approved page JSX only.
|
||||
- Do not touch `src/auth.ts`, credential validation, OIDC callbacks, token expiration, protected layout or API routes without separate approval.
|
||||
- No `mockUser`, hardcoded JWT, localStorage token, browser-side master key or administrative API calls.
|
||||
- ZITADEL user self-service link is an interim navigation aid; route access/feature availability is policy-dependent.
|
||||
- Auth.js uses browser redirects and server actions, never direct browser calls to token endpoints.
|
||||
|
||||
Sources:
|
||||
- https://zitadel.com/docs/sdk-examples/nextjs
|
||||
- https://authjs.dev/getting-started/installation?framework=Next.js
|
||||
- https://authjs.dev/getting-started/session-management/protecting
|
||||
- https://github.com/nextauthjs/next-auth/security/advisories/GHSA-8fpg-xm3f-6cx3
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// This file is managed by Next.js; avoid editing manually.
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
output: "standalone",
|
||||
poweredByHeader: false,
|
||||
reactStrictMode: true,
|
||||
async headers() {
|
||||
return [
|
||||
{
|
||||
source: "/(.*)",
|
||||
headers: [
|
||||
{ key: "X-Content-Type-Options", value: "nosniff" },
|
||||
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
|
||||
{ key: "X-Frame-Options", value: "DENY" },
|
||||
{ key: "Permissions-Policy", value: "camera=(), microphone=(), geolocation=()" }
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "@zitplane/account-portal",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "ZitPlane central account self-service portal",
|
||||
"engines": {
|
||||
"node": ">=22.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "16.4.3",
|
||||
"next-auth": "5.0.0-beta.32",
|
||||
"react": "19.2.6",
|
||||
"react-dom": "19.2.6",
|
||||
"server-only": "0.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "25.7.0",
|
||||
"@types/react": "19.2.14",
|
||||
"@types/react-dom": "19.2.3",
|
||||
"typescript": "5.9.3"
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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>;
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function Home() {
|
||||
redirect("/account");
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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! : ""
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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 & 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>
|
||||
);
|
||||
}
|
||||
@@ -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"
|
||||
};
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
Vendored
+16
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"plugins": [{ "name": "next" }],
|
||||
"paths": { "@/*": ["./src/*"] }
|
||||
},
|
||||
"include": ["next-env.d.ts", ".next/types/**/*.ts", ".next/dev/types/**/*.ts", "**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in new issue
Block a user