auth-yes/ui/components/AuthenticatedLayout.tsx

222 lines
6.2 KiB
TypeScript

export const AuthenticatedLayout = ({
children,
title,
currentPath,
isAdmin = false,
}: {
children: any;
title: string;
currentPath: string;
isAdmin?: boolean;
}) => {
const navItems = [
{ label: "Launchpad", href: "/dashboard" },
{ label: "Sessions", href: "/dashboard/sessions" },
{ label: "Passkeys", href: "/dashboard/passkeys" },
...(isAdmin ? [{ label: "Admin Console", href: "/admin/users" }] : []),
];
return (
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{title} - Auth-Yes</title>
<style>
{`
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: #f8f9fa;
margin: 0;
display: flex;
flex-direction: column;
min-height: 100vh;
}
.header {
background: #ffffff;
border-bottom: 1px solid #e9ecef;
padding: 1rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.header h1 {
margin: 0;
font-size: 1.25rem;
color: #212529;
}
.nav {
display: flex;
gap: 1.5rem;
}
.nav a {
text-decoration: none;
color: #495057;
font-weight: 500;
padding: 0.5rem 0;
}
.nav a:hover {
color: #007bff;
}
.nav a.active {
color: #007bff;
border-bottom: 2px solid #007bff;
}
.logout-btn {
background: none;
border: 1px solid #dc3545;
color: #dc3545;
padding: 0.4rem 1rem;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
}
.logout-btn:hover {
background: #dc3545;
color: white;
}
.main-content {
flex: 1;
padding: 2rem;
max-width: 1000px;
margin: 0 auto;
width: 100%;
box-sizing: border-box;
}
.card {
background: white;
padding: 1.5rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
margin-bottom: 1.5rem;
border: 1px solid #e9ecef;
}
h2 {
margin-top: 0;
color: #343a40;
font-size: 1.25rem;
border-bottom: 1px solid #e9ecef;
padding-bottom: 0.5rem;
margin-bottom: 1rem;
}
.table-container {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 0.75rem;
text-align: left;
border-bottom: 1px solid #dee2e6;
}
th {
background: #f8f9fa;
font-weight: 600;
color: #495057;
}
.btn-danger {
background: #dc3545;
color: white;
border: none;
padding: 0.4rem 0.8rem;
border-radius: 4px;
cursor: pointer;
font-size: 0.875rem;
}
.btn-danger:hover {
background: #c82333;
}
.btn-primary {
background: #007bff;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 4px;
cursor: pointer;
font-size: 0.9rem;
}
.btn-primary:hover {
background: #0069d9;
}
.badge {
display: inline-block;
padding: 0.25em 0.4em;
font-size: 75%;
font-weight: 700;
line-height: 1;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border-radius: 0.25rem;
}
.badge-success { background-color: #28a745; color: white; }
.badge-info { background-color: #17a2b8; color: white; }
.badge-secondary { background-color: #6c757d; color: white; }
`}
</style>
<script src="https://unpkg.com/@simplewebauthn/browser/dist/bundle/index.umd.min.js">
</script>
<script src="/public/auth-client.js?v=3"></script>
</head>
<body>
<header class="header">
<h1>Identity Provider</h1>
<nav class="nav">
{navItems.map((item) => {
const isActive = item.href === "/dashboard"
? currentPath === "/dashboard"
: currentPath.startsWith(item.href) &&
item.href !== "/dashboard";
return (
<a
href={item.href}
class={isActive ? "active" : ""}
>
{item.label}
</a>
);
})}
</nav>
<div
style={{
marginLeft: "auto",
marginRight: "1rem",
display: "flex",
gap: "1rem",
}}
>
{isAdmin && (
<a
href="/admin"
class="btn-primary"
style={{ textDecoration: "none" }}
>
Admin Console
</a>
)}
<a
href="/logout"
class="logout-btn"
style={{
textDecoration: "none",
display: "inline-block",
textAlign: "center",
}}
>
Logout
</a>
</div>
</header>
<main class="main-content">
{children}
</main>
</body>
</html>
);
};