update
This commit is contained in:
+21
-13
@@ -2,7 +2,9 @@ import type { Metadata } from "next";
|
||||
import "./globals.css";
|
||||
import TopNav from "@/components/TopNav";
|
||||
import Sidebar from "@/components/Sidebar";
|
||||
import { auth } from "@/auth";
|
||||
// --- SSO DISABLED FOR CICD TEST ---
|
||||
// import { auth } from "@/auth";
|
||||
// --- END SSO DISABLED ---
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Global IT Cost Dashboard",
|
||||
@@ -14,19 +16,25 @@ export default async function RootLayout({
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const session = await auth();
|
||||
// --- SSO DISABLED FOR CICD TEST ---
|
||||
// const session = await auth();
|
||||
//
|
||||
// // Unauthenticated (e.g. the /login page) -> render a bare shell with no
|
||||
// // sidebar/topnav so the sign-in screen shows on its own.
|
||||
// if (!session?.user) {
|
||||
// return (
|
||||
// <html lang="en">
|
||||
// <body>{children}</body>
|
||||
// </html>
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// const isAdmin = session.user.role === "admin";
|
||||
|
||||
// Unauthenticated (e.g. the /login page) -> render a bare shell with no
|
||||
// sidebar/topnav so the sign-in screen shows on its own.
|
||||
if (!session?.user) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
const isAdmin = session.user.role === "admin";
|
||||
// Hardcoded so the sidebar/topnav still render — auth() would return null
|
||||
// with SSO off and the whole UI chrome would vanish.
|
||||
const isAdmin = true;
|
||||
// --- END SSO DISABLED ---
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
|
||||
@@ -14,11 +14,13 @@ function errorMessage(code: string | undefined): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
// --- SSO DISABLED FOR CICD TEST ---
|
||||
// Server action: kick off the Microsoft SSO flow.
|
||||
async function microsoftLogin() {
|
||||
"use server";
|
||||
await signIn("microsoft-entra-id", { redirectTo: "/" });
|
||||
}
|
||||
// async function microsoftLogin() {
|
||||
// "use server";
|
||||
// await signIn("microsoft-entra-id", { redirectTo: "/" });
|
||||
// }
|
||||
// --- END SSO DISABLED ---
|
||||
|
||||
// Server action: local username/password login.
|
||||
async function credentialsLogin(formData: FormData) {
|
||||
@@ -63,6 +65,7 @@ export default async function LoginPage({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* --- SSO DISABLED FOR CICD TEST ---
|
||||
<form action={microsoftLogin} className="mt-6">
|
||||
<button
|
||||
type="submit"
|
||||
@@ -77,8 +80,9 @@ export default async function LoginPage({
|
||||
OR
|
||||
<span className="h-px flex-1 bg-[#E5E7EB]" />
|
||||
</div>
|
||||
--- END SSO DISABLED --- */}
|
||||
|
||||
<form action={credentialsLogin} className="flex flex-col gap-3">
|
||||
<form action={credentialsLogin} className="mt-6 flex flex-col gap-3">
|
||||
<label className="flex flex-col gap-1 text-sm text-[#374151]">
|
||||
Username
|
||||
<input
|
||||
|
||||
+36
-24
@@ -1,44 +1,56 @@
|
||||
import { auth, signIn, signOut } from "@/auth";
|
||||
// --- SSO DISABLED FOR CICD TEST ---
|
||||
// import { auth, signIn, signOut } from "@/auth";
|
||||
// --- END SSO DISABLED ---
|
||||
|
||||
export default async function TopNav() {
|
||||
const session = await auth();
|
||||
const user = session?.user;
|
||||
// --- SSO DISABLED FOR CICD TEST ---
|
||||
// const session = await auth();
|
||||
// const user = session?.user;
|
||||
const user = { name: "CI Test User" };
|
||||
// --- END SSO DISABLED ---
|
||||
|
||||
return (
|
||||
<header className="flex h-14 items-center justify-between bg-[#111827] px-6 text-white">
|
||||
<span className="text-lg font-semibold">Global IT Cost Dashboard</span>
|
||||
{user ? (
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm text-white/80">{user.name ?? user.email}</span>
|
||||
{/* --- SSO DISABLED FOR CICD TEST ---
|
||||
Original: `{user ? (<logged-in block/>) : (<login form/>)}`. Both forms
|
||||
are server actions calling signOut/signIn, which would throw without
|
||||
the Entra env vars, so only the name is rendered below.
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm text-white/80">{user.name ?? user.email}</span>
|
||||
<form
|
||||
action={async () => {
|
||||
"use server";
|
||||
await signOut({ redirectTo: "/" });
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-md bg-white/10 px-4 py-1.5 text-sm font-medium hover:bg-white/20"
|
||||
>
|
||||
Logout
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<form
|
||||
action={async () => {
|
||||
"use server";
|
||||
await signOut({ redirectTo: "/" });
|
||||
await signIn("microsoft-entra-id");
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-md bg-white/10 px-4 py-1.5 text-sm font-medium hover:bg-white/20"
|
||||
>
|
||||
Logout
|
||||
Login
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
) : (
|
||||
<form
|
||||
action={async () => {
|
||||
"use server";
|
||||
await signIn("microsoft-entra-id");
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-md bg-white/10 px-4 py-1.5 text-sm font-medium hover:bg-white/20"
|
||||
>
|
||||
Login
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
--- END SSO DISABLED --- */}
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm text-white/80">{user.name}</span>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
+14
-10
@@ -1,14 +1,18 @@
|
||||
import NextAuth from "next-auth";
|
||||
import { authConfig } from "@/auth.config";
|
||||
// --- SSO DISABLED FOR CICD TEST ---
|
||||
// Original: protect the whole app with role-aware auth in the edge runtime.
|
||||
// import NextAuth from "next-auth";
|
||||
// import { authConfig } from "@/auth.config";
|
||||
//
|
||||
// export const { auth: middleware } = NextAuth(authConfig);
|
||||
|
||||
// Protect the whole app with role-aware auth. Runs in the edge runtime, so it
|
||||
// uses the edge-safe authConfig (no node:fs / providers). The `authorized`
|
||||
// callback there redirects unauthenticated users to /login and blocks normal
|
||||
// users from admin pages / write APIs.
|
||||
export const { auth: middleware } = NextAuth(authConfig);
|
||||
// No-op replacement. The EMPTY MATCHER below is the actual kill switch — this
|
||||
// function is never invoked, and every route (including the three admin pages)
|
||||
// is open.
|
||||
export function middleware() {}
|
||||
|
||||
export const config = {
|
||||
// Run on everything EXCEPT: the auth endpoints (must stay public so users can
|
||||
// sign in), Next.js internals, and static asset requests (files with a dot).
|
||||
matcher: ["/((?!api/auth|_next/static|_next/image|favicon.ico|.*\\.).*)"],
|
||||
// Original matcher (restore with the lines above):
|
||||
// matcher: ["/((?!api/auth|_next/static|_next/image|favicon.ico|.*\\.).*)"],
|
||||
matcher: [],
|
||||
};
|
||||
// --- END SSO DISABLED ---
|
||||
|
||||
Reference in New Issue
Block a user