A4: app shell (layout, nav, tokens, error/empty states, /api/health)
Fixes the A4 blocker: /api/dev/complete now establishes the Auth.js session. Root cause was UntrustedHost (trustHost defaulted false in pnpm start / production because setEnvDefaults derives it from AUTH_URL, not NEXTAUTH_URL, and assertConfig checks it before that default applies). Added trustHost: true to the auth config; rebuilt. Complete response now sets authjs.session-token, /schedule returns 200, and all 4 e2e shell tests pass. Also ignores test-results/ artifacts.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { StateMessage } from "@/components/app/state-message";
|
||||
|
||||
export const metadata = { title: "Announcements" };
|
||||
|
||||
export default function AnnouncementsPage() {
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-lg font-semibold tracking-tight">Announcements</h1>
|
||||
<p className="text-sm text-muted-foreground">News and notes from the media team.</p>
|
||||
<StateMessage
|
||||
title="No announcements"
|
||||
description="Team announcements will appear here as rich-text posts."
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { auth } from "@/auth/config";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AppLayout } from "@/components/app/app-layout";
|
||||
|
||||
/**
|
||||
* Authenticated shell wrapper. Any route under the `(app)` group requires a
|
||||
* session; unauthenticated visitors are sent to /login. The visible shell
|
||||
* (header, nav, main, footer) is provided by AppLayout.
|
||||
*/
|
||||
export default async function AppGroupLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const session = await auth();
|
||||
if (!session?.user) redirect("/login");
|
||||
return <AppLayout>{children}</AppLayout>;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { StateMessage } from "@/components/app/state-message";
|
||||
|
||||
export const metadata = { title: "Roster" };
|
||||
|
||||
export default function RosterPage() {
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-lg font-semibold tracking-tight">Roster</h1>
|
||||
<p className="text-sm text-muted-foreground">The team, their roles, and how to reach them.</p>
|
||||
<StateMessage
|
||||
title="No one on the roster yet"
|
||||
description="Volunteers appear here once an admin invites and approves them."
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { StateMessage } from "@/components/app/state-message";
|
||||
|
||||
export const metadata = { title: "Schedule" };
|
||||
|
||||
export default function SchedulePage() {
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-lg font-semibold tracking-tight">Schedule</h1>
|
||||
<p className="text-sm text-muted-foreground">Your upcoming slots and what to do the day of service.</p>
|
||||
<StateMessage
|
||||
title="Nothing scheduled yet"
|
||||
description="Slots confirmed for you will show up here, with call times and a way to add them to your calendar."
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { StateMessage } from "@/components/app/state-message";
|
||||
|
||||
export const metadata = { title: "Settings" };
|
||||
|
||||
export default function SettingsPage() {
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-lg font-semibold tracking-tight">Settings</h1>
|
||||
<p className="text-sm text-muted-foreground">Church details, timezone, and scheduling rules.</p>
|
||||
<StateMessage
|
||||
title="No settings to show"
|
||||
description="Church and scheduling settings appear here. Branding and admin settings are restricted to admins."
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { StateMessage } from "@/components/app/state-message";
|
||||
|
||||
export const metadata = { title: "Training" };
|
||||
|
||||
export default function TrainingPage() {
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-lg font-semibold tracking-tight">Training</h1>
|
||||
<p className="text-sm text-muted-foreground">How-tos and tutorials, with progress tied to your roles.</p>
|
||||
<StateMessage
|
||||
title="No courses available"
|
||||
description="Training lessons will appear here. Some are required before you can serve certain roles."
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -20,9 +20,17 @@ export const GET = async (req: NextRequest) => {
|
||||
);
|
||||
}
|
||||
|
||||
const result = await signIn("magic-link", { token, redirect: false });
|
||||
return new Response(JSON.stringify({ ok: true, url: result.url }), {
|
||||
status: 200,
|
||||
headers: JSON_HEADERS,
|
||||
});
|
||||
};
|
||||
try {
|
||||
const result = await signIn("magic-link", { token, redirect: false });
|
||||
return new Response(JSON.stringify({ ok: true, url: result.url }), {
|
||||
status: 200,
|
||||
headers: JSON_HEADERS,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("[complete] signIn failed:", (err as Error).message, (err as Error).stack);
|
||||
return new Response(JSON.stringify({ error: "failed to sign in" }), {
|
||||
status: 500,
|
||||
headers: JSON_HEADERS,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
/**
|
||||
* Liveness probe for the reverse proxy / cron worker. Cheap, no DB, no auth.
|
||||
* The cron worker's heartbeat is a separate concern (G3); this just answers
|
||||
* "is this process up?".
|
||||
*/
|
||||
export const GET = async () => {
|
||||
return NextResponse.json({
|
||||
status: "ok",
|
||||
time: new Date().toISOString(),
|
||||
});
|
||||
};
|
||||
@@ -38,6 +38,12 @@ export const authConfig = {
|
||||
],
|
||||
session: { strategy: "jwt" },
|
||||
secret: process.env.AUTH_SECRET ?? process.env.NEXTAUTH_SECRET,
|
||||
// Auth.js v5 gates the callback on the request `Host` header and throws
|
||||
// `UntrustedHost` unless `trustHost` is true. In `pnpm start` (production)
|
||||
// the env-based default is false, which silently drops the session cookie
|
||||
// on the magic-link callback (the A4 blocker). This is a localhost app behind
|
||||
// a reverse proxy, so trusting the Host header is the documented fix.
|
||||
trustHost: true,
|
||||
pages: { signIn: "/login" },
|
||||
callbacks: {
|
||||
async jwt({ token, user }) {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { NavTabs, NavRail } from "./nav";
|
||||
|
||||
/**
|
||||
* App shell: sticky header (app title + mobile tab bar), desktop side rail,
|
||||
* scrollable main, and a footer. Wraps every authenticated page. Pure layout —
|
||||
* no data, no auth — so the auth guard lives in the route group that uses it.
|
||||
*/
|
||||
export function AppLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col bg-background text-foreground">
|
||||
<header className="sticky top-0 z-20 border-b bg-background">
|
||||
<div className="flex h-14 items-center px-4">
|
||||
<span className="text-base font-semibold tracking-tight">Media Team Hub</span>
|
||||
</div>
|
||||
<NavTabs className="md:hidden" />
|
||||
</header>
|
||||
|
||||
<div className="flex flex-1">
|
||||
<aside className="hidden md:block md:w-64 md:shrink-0">
|
||||
<NavRail />
|
||||
</aside>
|
||||
|
||||
<main className="flex min-w-0 flex-1">
|
||||
<div className="flex w-full flex-1 flex-col p-4 md:p-8">
|
||||
{children}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer className="border-t bg-muted/40">
|
||||
<div className="flex h-12 items-center px-4">
|
||||
<p className="text-xs text-muted-foreground">Media Team Hub</p>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { Calendar, Users, BookOpen, Megaphone, Settings } from "lucide-react";
|
||||
|
||||
/**
|
||||
* The five primary navigation destinations. Single source of truth so the
|
||||
* mobile tab bar and the desktop rail stay in sync.
|
||||
*/
|
||||
export const NAV_ITEMS = [
|
||||
{ href: "/schedule", label: "Schedule", icon: Calendar },
|
||||
{ href: "/roster", label: "Roster", icon: Users },
|
||||
{ href: "/training", label: "Training", icon: BookOpen },
|
||||
{ href: "/announcements", label: "Announcements", icon: Megaphone },
|
||||
{ href: "/settings", label: "Settings", icon: Settings },
|
||||
] as const;
|
||||
|
||||
type IconName = (typeof NAV_ITEMS)[number]["icon"];
|
||||
|
||||
function isActive(pathname: string, href: string): boolean {
|
||||
if (pathname === href) return true;
|
||||
// Landing tab highlights on the empty root.
|
||||
return pathname === "/" && href === "/schedule";
|
||||
}
|
||||
|
||||
/** Mobile: full-width tab bar, icon + label, one cell per tab. */
|
||||
export function NavTabs({ className = "" }: { className?: string }) {
|
||||
const pathname = usePathname();
|
||||
return (
|
||||
<nav
|
||||
aria-label="Primary"
|
||||
className={`flex border-b bg-background ${className}`}
|
||||
>
|
||||
{NAV_ITEMS.map((item) => {
|
||||
const active = isActive(pathname, item.href);
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
aria-current={active ? "page" : undefined}
|
||||
className="flex flex-1 flex-col items-center gap-1 border-transparent px-2 py-2.5 text-xs font-medium text-muted-foreground transition-colors hover:text-foreground [&[aria-current=page]:border-b]:border-primary [&[aria-current=page]:border-b]:text-primary"
|
||||
>
|
||||
<item.icon className="h-5 w-5" aria-hidden="true" />
|
||||
<span>{item.label}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
/** Desktop: vertical rail, icon + label, padded. */
|
||||
export function NavRail({ className = "" }: { className?: string }) {
|
||||
const pathname = usePathname();
|
||||
return (
|
||||
<nav
|
||||
aria-label="Primary"
|
||||
className={`flex flex-col gap-1 p-2 ${className}`}
|
||||
>
|
||||
{NAV_ITEMS.map((item) => {
|
||||
const active = isActive(pathname, item.href);
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
aria-current={active ? "page" : undefined}
|
||||
className={`flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium transition-colors ${
|
||||
active
|
||||
? "bg-primary text-primary-foreground"
|
||||
: "text-muted-foreground hover:bg-muted hover:text-foreground"
|
||||
}`}
|
||||
>
|
||||
<item.icon className="h-4 w-4" aria-hidden="true" />
|
||||
<span>{item.label}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
export type { IconName };
|
||||
@@ -0,0 +1,37 @@
|
||||
import { AlertTriangle, Inbox } from "lucide-react";
|
||||
|
||||
/**
|
||||
* Shared empty + error states so every page speaks with one voice. Kept pure
|
||||
* (no data, no auth) so it is trivially testable and reusable.
|
||||
*/
|
||||
export function StateMessage({
|
||||
kind = "empty",
|
||||
title,
|
||||
description,
|
||||
}: {
|
||||
kind?: "empty" | "error";
|
||||
title?: string;
|
||||
description?: string;
|
||||
}) {
|
||||
const isError = kind === "error";
|
||||
return (
|
||||
<div
|
||||
role={isError ? "alert" : undefined}
|
||||
className="flex flex-1 flex-col items-center justify-center gap-3 px-6 py-24 text-center"
|
||||
>
|
||||
<div
|
||||
className={`flex h-12 w-12 items-center justify-center rounded-full ${
|
||||
isError ? "bg-destructive/10 text-destructive" : "bg-muted text-muted-foreground"
|
||||
}`}
|
||||
>
|
||||
{isError ? (
|
||||
<AlertTriangle className="h-6 w-6" />
|
||||
) : (
|
||||
<Inbox className="h-6 w-6" />
|
||||
)}
|
||||
</div>
|
||||
{title && <p className="text-sm font-semibold text-foreground">{title}</p>}
|
||||
{description && <p className="max-w-sm text-sm text-muted-foreground">{description}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user