372 lines
12 KiB
TypeScript
372 lines
12 KiB
TypeScript
import { COMMON_CSS } from "./CommonStyles.ts";
|
|
|
|
export const AuthenticatedLayout = ({
|
|
children,
|
|
title,
|
|
currentPath,
|
|
isAdmin = false,
|
|
}: {
|
|
children: any;
|
|
title: string;
|
|
currentPath: string;
|
|
isAdmin?: boolean;
|
|
}) => {
|
|
const navItems = [
|
|
{
|
|
label: "Launchpad",
|
|
href: "/dashboard",
|
|
icon:
|
|
`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"></path><path d="m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"></path><path d="M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"></path><path d="M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"></path></svg>`,
|
|
},
|
|
{
|
|
label: "Sessions",
|
|
href: "/dashboard/sessions",
|
|
icon:
|
|
`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="3" rx="2"></rect><line x1="8" x2="16" y1="21" y2="21"></line><line x1="12" x2="12" y1="17" y2="21"></line></svg>`,
|
|
},
|
|
{
|
|
label: "Passkeys",
|
|
href: "/dashboard/passkeys",
|
|
icon:
|
|
`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="7.5" cy="15.5" r="5.5"></circle><path d="m21 2-9.6 9.6"></path><path d="m15.5 7.5 3 3L22 7l-3-3"></path></svg>`,
|
|
},
|
|
...(isAdmin
|
|
? [{
|
|
label: "Admin",
|
|
href: "/admin/users",
|
|
icon:
|
|
`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path></svg>`,
|
|
}]
|
|
: []),
|
|
];
|
|
|
|
return (
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta
|
|
name="viewport"
|
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
|
/>
|
|
<meta name="theme-color" content="#0066cc" />
|
|
<title>{title} - Auth-Yes</title>
|
|
<style>
|
|
{`
|
|
${COMMON_CSS}
|
|
|
|
/* Layout Shell */
|
|
.app-shell {
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
/* Top App Bar */
|
|
.top-bar {
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 40;
|
|
background-color: var(--surface-card);
|
|
border-bottom: 1px solid var(--border-subtle);
|
|
padding: 0.75rem 1.25rem;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
box-shadow: var(--shadow-sm);
|
|
}
|
|
|
|
.brand {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.65rem;
|
|
text-decoration: none;
|
|
color: var(--text-primary);
|
|
font-weight: 700;
|
|
font-size: 1.15rem;
|
|
height: 36px;
|
|
}
|
|
|
|
.brand-badge {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 32px;
|
|
height: 32px;
|
|
background: var(--primary);
|
|
color: #ffffff;
|
|
border-radius: var(--radius-sm);
|
|
font-weight: 800;
|
|
}
|
|
|
|
/* Desktop Navigation */
|
|
.desktop-nav {
|
|
display: none;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
margin-left: 2rem;
|
|
}
|
|
|
|
.desktop-nav a {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.4rem;
|
|
padding: 0.4rem 0.85rem;
|
|
border-radius: var(--radius-md);
|
|
text-decoration: none;
|
|
color: var(--text-secondary);
|
|
font-weight: 500;
|
|
font-size: 0.9rem;
|
|
height: 36px;
|
|
box-sizing: border-box;
|
|
transition: all 0.15s ease;
|
|
}
|
|
|
|
.desktop-nav a:hover {
|
|
background-color: var(--surface-muted);
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.desktop-nav a.active {
|
|
background-color: var(--primary-light);
|
|
color: var(--primary);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.header-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
}
|
|
|
|
.logout-link {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.35rem;
|
|
padding: 0.4rem 0.85rem;
|
|
border-radius: var(--radius-md);
|
|
text-decoration: none;
|
|
color: var(--danger);
|
|
font-weight: 600;
|
|
font-size: 0.85rem;
|
|
border: 1px solid var(--danger-border);
|
|
background: var(--danger-bg);
|
|
height: 36px;
|
|
box-sizing: border-box;
|
|
transition: all 0.15s ease;
|
|
}
|
|
|
|
.logout-link:hover {
|
|
background: var(--danger);
|
|
color: #ffffff;
|
|
}
|
|
|
|
/* Main Content Container */
|
|
.main-content {
|
|
flex: 1;
|
|
width: 100%;
|
|
max-width: 1100px;
|
|
margin: 0 auto;
|
|
padding: 1.5rem 1rem calc(5.5rem + env(safe-area-inset-bottom)) 1rem;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
/* Mobile Bottom Navigation Bar */
|
|
.mobile-bottom-nav {
|
|
position: fixed;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
z-index: 50;
|
|
background-color: var(--surface-card);
|
|
border-top: 1px solid var(--border-subtle);
|
|
display: flex;
|
|
justify-content: space-around;
|
|
padding: 0.5rem 0 calc(0.5rem + env(safe-area-inset-bottom)) 0;
|
|
box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.04);
|
|
}
|
|
|
|
.mobile-bottom-nav a {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 0.2rem;
|
|
color: var(--text-muted);
|
|
text-decoration: none;
|
|
font-size: 0.75rem;
|
|
font-weight: 600;
|
|
padding: 0.35rem 0.75rem;
|
|
border-radius: var(--radius-md);
|
|
transition: all 0.15s ease;
|
|
min-width: 64px;
|
|
}
|
|
|
|
.mobile-bottom-nav a.active {
|
|
color: var(--primary);
|
|
}
|
|
|
|
.mobile-bottom-nav a.active svg {
|
|
stroke: var(--primary);
|
|
}
|
|
|
|
/* Desktop Responsive Rules */
|
|
@media (min-width: 768px) {
|
|
.desktop-nav {
|
|
display: flex;
|
|
}
|
|
.mobile-bottom-nav {
|
|
display: none;
|
|
}
|
|
.main-content {
|
|
padding: 2.5rem 2rem;
|
|
}
|
|
.top-bar {
|
|
padding: 0.75rem 2rem;
|
|
}
|
|
}
|
|
|
|
/* Tables Responsive Scroller */
|
|
.table-container {
|
|
width: 100%;
|
|
overflow-x: auto;
|
|
-webkit-overflow-scrolling: touch;
|
|
border-radius: var(--radius-md);
|
|
border: 1px solid var(--border-subtle);
|
|
}
|
|
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
text-align: left;
|
|
}
|
|
|
|
th, td {
|
|
padding: 0.85rem 1rem;
|
|
border-bottom: 1px solid var(--border-subtle);
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
th {
|
|
background-color: var(--surface-muted);
|
|
color: var(--text-secondary);
|
|
font-weight: 600;
|
|
}
|
|
|
|
tr:last-child td {
|
|
border-bottom: none;
|
|
}
|
|
`}
|
|
</style>
|
|
<script src="https://unpkg.com/@simplewebauthn/browser/dist/bundle/index.umd.min.js">
|
|
</script>
|
|
<script src="/public/auth-client.js?v=5"></script>
|
|
</head>
|
|
<body>
|
|
<div class="app-shell">
|
|
{/* Top Header */}
|
|
<header class="top-bar">
|
|
<div style="display: flex; align-items: center;">
|
|
<a href="/dashboard" class="brand">
|
|
<span class="brand-badge">AY</span>
|
|
<span>Auth-Yes</span>
|
|
</a>
|
|
|
|
{/* Desktop Nav Links */}
|
|
<nav class="desktop-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" : ""}
|
|
>
|
|
<span dangerouslySetInnerHTML={{ __html: item.icon }} />
|
|
<span>{item.label}</span>
|
|
</a>
|
|
);
|
|
})}
|
|
</nav>
|
|
</div>
|
|
|
|
<div class="header-actions">
|
|
{isAdmin && (
|
|
<a
|
|
href="/admin/users"
|
|
class="btn-primary"
|
|
style="padding: 0.4rem 0.85rem; font-size: 0.85rem; min-height: 36px; height: 36px; box-sizing: border-box; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;"
|
|
>
|
|
<svg
|
|
width="15"
|
|
height="15"
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
stroke-width="2"
|
|
stroke-linecap="round"
|
|
stroke-linejoin="round"
|
|
>
|
|
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z">
|
|
</path>
|
|
</svg>
|
|
<span>Admin Console</span>
|
|
</a>
|
|
)}
|
|
<a
|
|
href="/logout"
|
|
class="logout-link"
|
|
title="Sign out of your session"
|
|
>
|
|
<svg
|
|
width="16"
|
|
height="16"
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
stroke-width="2"
|
|
stroke-linecap="round"
|
|
stroke-linejoin="round"
|
|
>
|
|
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"></path>
|
|
<polyline points="16 17 21 12 16 7"></polyline>
|
|
<line x1="21" x2="9" y1="12" y2="12"></line>
|
|
</svg>
|
|
<span>Logout</span>
|
|
</a>
|
|
</div>
|
|
</header>
|
|
|
|
{/* Main Body */}
|
|
<main class="main-content">
|
|
{children}
|
|
</main>
|
|
|
|
{/* Mobile Bottom Navigation Bar */}
|
|
<nav class="mobile-bottom-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" : ""}
|
|
>
|
|
<span dangerouslySetInnerHTML={{ __html: item.icon }} />
|
|
<span>{item.label}</span>
|
|
</a>
|
|
);
|
|
})}
|
|
</nav>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
);
|
|
};
|