Scaffold Homelab Manager foundation

Monorepo (Express+TS+Drizzle/libSQL server, React+Vite+Tabler web) matching
the stack used by ScheduleTaskManager and Sloth Manager. Includes Authentik
OIDC login with local admin/operator/viewer roles (first user becomes admin),
a generalized audit log, encrypted-at-rest storage for future integration API
tokens, the DB schema for all planned modules, and the Tabler-styled app
shell/nav. Also ports the Secrets (expiry tracker) and IP Addresses (IPAM)
modules from Sloth Manager onto the new stack.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5 committed 2026-09-14 21:57:13 +02:00
commit 6bd2ed52c1
52 files changed
+8103

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
import { eq } from "drizzle-orm";
import { db } from "../db/client.js";
import { users } from "../db/schema.js";
/**
* Called on every successful OIDC login. The very first user ever to sign in
* becomes admin; everyone after defaults to viewer until an admin promotes
* them from the Users page.
*/
export async function upsertUserFromLogin(params: {
sub: string;
email?: string;
name?: string;
}) {
const [existing] = await db.select().from(users).where(eq(users.oidcSub, params.sub)).limit(1);
const now = new Date().toISOString();
if (existing) {
const [updated] = await db
.update(users)
.set({
email: params.email ?? existing.email,
name: params.name ?? existing.name,
lastLoginAt: now,
})
.where(eq(users.id, existing.id))
.returning();
return updated;
}
const anyUser = await db.select({ id: users.id }).from(users).limit(1);
const role = anyUser.length === 0 ? ("admin" as const) : ("viewer" as const);
const [created] = await db
.insert(users)
.values({
oidcSub: params.sub,
email: params.email,
name: params.name,
role,
lastLoginAt: now,
})
.returning();
return created;
}