- Replace next-auth v5 beta with better-auth v1.6.2 (stable releases)
- Add multi-provider OAuth support with admin UI configuration
- New oauthProviders table with encrypted secrets (AES-256-GCM)
- Env var bootstrap (OAUTH_*) syncs to DB, UI-created providers fully editable
- OAuth provider REST API: GET/POST/PUT/DELETE /api/v1/oauth-providers
- Settings page "Authentication Providers" section for admin management
- Account linking uses new accounts table (multi-provider per user)
- Username plugin for credentials sign-in (replaces email@localhost pattern)
- bcrypt password compatibility (existing hashes work)
- Database-backed sessions via Kysely adapter (bun:sqlite direct)
- Configurable rate limiting via AUTH_RATE_LIMIT_* env vars
- All DB columns migrated from snake_case to camelCase
- All TypeScript types/models migrated to camelCase properties
- Removed casing: "snake_case" from Drizzle config
- Callback URL format: {baseUrl}/api/auth/oauth2/callback/{providerId}
- package-lock.json removed and gitignored (using bun.lock)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
90 lines
3.1 KiB
TypeScript
90 lines
3.1 KiB
TypeScript
import db, { toIso } from "@/src/lib/db";
|
|
import { requireUser } from "@/src/lib/auth";
|
|
import OverviewClient from "./OverviewClient";
|
|
import {
|
|
accessLists,
|
|
auditEvents,
|
|
certificates,
|
|
proxyHosts
|
|
} from "@/src/lib/db/schema";
|
|
import { count, desc, isNull, sql } from "drizzle-orm";
|
|
import { ArrowLeftRight, ShieldCheck, KeyRound } from "lucide-react";
|
|
import { ReactNode } from "react";
|
|
import { getAnalyticsSummary } from "@/src/lib/analytics-db";
|
|
|
|
type StatCard = {
|
|
label: string;
|
|
icon: ReactNode;
|
|
count: number;
|
|
href: string;
|
|
};
|
|
|
|
async function loadStats(): Promise<StatCard[]> {
|
|
const [proxyHostCountResult, acmeCertCountResult, importedCertCountResult, accessListCountResult] =
|
|
await Promise.all([
|
|
db.select({ value: count() }).from(proxyHosts),
|
|
// Proxy hosts with no explicit cert → Caddy auto-issues one ACME cert per host
|
|
db.select({ value: count() }).from(proxyHosts).where(isNull(proxyHosts.certificateId)),
|
|
// Imported certs with actual PEM data (valid, user-managed)
|
|
db.select({ value: count() }).from(certificates).where(
|
|
sql`${certificates.type} = 'imported' AND ${certificates.certificatePem} IS NOT NULL`
|
|
),
|
|
db.select({ value: count() }).from(accessLists)
|
|
]);
|
|
const proxyHostsCount = proxyHostCountResult[0]?.value ?? 0;
|
|
const certificatesCount = (acmeCertCountResult[0]?.value ?? 0) + (importedCertCountResult[0]?.value ?? 0);
|
|
const accessListsCount = accessListCountResult[0]?.value ?? 0;
|
|
|
|
return [
|
|
{ label: "Proxy Hosts", icon: <ArrowLeftRight className="h-4 w-4" />, count: proxyHostsCount, href: "/proxy-hosts" },
|
|
{ label: "Certificates", icon: <ShieldCheck className="h-4 w-4" />, count: certificatesCount, href: "/certificates" },
|
|
{ label: "Access Lists", icon: <KeyRound className="h-4 w-4" />, count: accessListsCount, href: "/access-lists" }
|
|
];
|
|
}
|
|
|
|
export default async function OverviewPage() {
|
|
const session = await requireUser();
|
|
const isAdmin = session.user.role === "admin";
|
|
|
|
// Non-admin users see a minimal welcome page
|
|
if (!isAdmin) {
|
|
return (
|
|
<OverviewClient
|
|
userName={session.user.name ?? session.user.email ?? "User"}
|
|
stats={[]}
|
|
trafficSummary={null}
|
|
recentEvents={[]}
|
|
isAdmin={false}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const [stats, trafficSummary, recentEventsRaw] = await Promise.all([
|
|
loadStats(),
|
|
getAnalyticsSummary(Math.floor(Date.now() / 1000) - 86400, Math.floor(Date.now() / 1000), []).catch(() => null),
|
|
db
|
|
.select({
|
|
action: auditEvents.action,
|
|
entityType: auditEvents.entityType,
|
|
summary: auditEvents.summary,
|
|
createdAt: auditEvents.createdAt
|
|
})
|
|
.from(auditEvents)
|
|
.orderBy(desc(auditEvents.createdAt))
|
|
.limit(8),
|
|
]);
|
|
|
|
return (
|
|
<OverviewClient
|
|
userName={session.user.name ?? session.user.email ?? "Admin"}
|
|
stats={stats}
|
|
trafficSummary={trafficSummary}
|
|
isAdmin={true}
|
|
recentEvents={recentEventsRaw.map((event) => ({
|
|
summary: event.summary ?? `${event.action} on ${event.entityType}`,
|
|
createdAt: toIso(event.createdAt)!
|
|
}))}
|
|
/>
|
|
);
|
|
}
|