Hub v1: install API, licences, health dashboard, alerts
- Protocol 1 (docs/hub-protocol.md): public key, register, signed heartbeats - Ed25519 licence tokens (30-day validity, status, expiry, grace, limits) - Dashboard: installs, install detail, customers and licences, alerts, settings and audit log; two-factor login required - Alert checks every 5 minutes, emailed once; heartbeat roll-up after 30 days - Unit tests for encryption, tokens, signatures, TOTP and alert rules Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012mt6TCv85T9VKRq3cV7rXq
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { LayoutDashboard, Building2, BellRing, Settings, LogOut } from "lucide-react";
|
||||
import { api, getToken, setToken } from "@/lib/api";
|
||||
|
||||
type Me = { id: string; name: string; email: string };
|
||||
|
||||
const NAV = [
|
||||
{ href: "/", label: "Installs", icon: LayoutDashboard },
|
||||
{ href: "/customers", label: "Customers", icon: Building2 },
|
||||
{ href: "/alerts", label: "Alerts", icon: BellRing },
|
||||
{ href: "/settings", label: "Settings", icon: Settings },
|
||||
];
|
||||
|
||||
/** Everything except /login: requires a session, with the side navigation. */
|
||||
export default function HubLayout({ children }: { children: React.ReactNode }) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const [me, setMe] = useState<Me | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!getToken()) { router.replace("/login"); return; }
|
||||
api<Me>("/api/auth/me").then(setMe).catch(() => router.replace("/login"));
|
||||
}, [router]);
|
||||
|
||||
if (!me) return <div className="flex min-h-screen items-center justify-center text-sm text-slate-400">Loading…</div>;
|
||||
|
||||
const active = (href: string) => (href === "/" ? pathname === "/" || pathname.startsWith("/installs") : pathname.startsWith(href));
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen">
|
||||
<aside className="hidden w-56 shrink-0 border-r border-slate-200 bg-white p-4 md:flex md:flex-col">
|
||||
<div className="mb-6 px-2">
|
||||
<div className="text-base font-semibold">Hope Events Hub</div>
|
||||
<div className="text-xs text-slate-500">{me.name}</div>
|
||||
</div>
|
||||
<nav className="space-y-1">
|
||||
{NAV.map(n => {
|
||||
const Icon = n.icon;
|
||||
return (
|
||||
<Link key={n.href} href={n.href} className={`flex items-center gap-2 rounded-lg px-3 py-2 text-sm ${active(n.href) ? "bg-indigo-50 font-medium text-indigo-700" : "text-slate-600 hover:bg-slate-50"}`}>
|
||||
<Icon className="h-4 w-4" /> {n.label}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
<button onClick={() => { setToken(null); router.replace("/login"); }} className="mt-auto flex items-center gap-2 rounded-lg px-3 py-2 text-sm text-slate-600 hover:bg-slate-50">
|
||||
<LogOut className="h-4 w-4" /> Sign out
|
||||
</button>
|
||||
</aside>
|
||||
<div className="flex-1 min-w-0">
|
||||
<nav className="flex gap-1 overflow-x-auto border-b border-slate-200 bg-white px-3 py-2 md:hidden">
|
||||
{NAV.map(n => (
|
||||
<Link key={n.href} href={n.href} className={`whitespace-nowrap rounded-lg px-3 py-1.5 text-sm ${active(n.href) ? "bg-indigo-50 font-medium text-indigo-700" : "text-slate-600"}`}>{n.label}</Link>
|
||||
))}
|
||||
</nav>
|
||||
<main className="mx-auto max-w-6xl p-4 md:p-8">{children}</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user