--- import { getDatabase, schema } from "@/db"; import BaseLayout from "@/layouts/BaseLayout.astro"; import { asc, eq } from "drizzle-orm"; import type { NodePgDatabase } from "drizzle-orm/node-postgres"; import UserProfileView from "@/components/profile/UserProfileView.astro"; import ServerDirectoryBar from "@/components/profile/ServerDirectoryBar.astro"; const db = getDatabase() as NodePgDatabase; const tab = Astro.url.searchParams.get("tab") || "overview"; // 1. Determine the primary profile to display on the landing page let primaryUser: typeof schema.users.$inferSelect | null = null; try { // If a user is logged in, show their profile (GitHub-style landing) const loggedInUser = Astro.locals.user; if (loggedInUser) { primaryUser = loggedInUser as any; } else { // Anonymous visitors: prefer the first admin, then first active user const adminUser = await db.query.users.findFirst({ where: eq(schema.users.isAdmin, true), orderBy: [asc(schema.users.createdAt)], }); if (adminUser) { primaryUser = adminUser; } else { // Find any first user const firstUser = await db.query.users.findFirst({ where: eq(schema.users.isActive, true), orderBy: [asc(schema.users.createdAt)], }); primaryUser = firstUser || null; } } } catch (e) { console.error("Error resolving landing page user profile:", e); } // Fallback if the database has no users yet — generic placeholder so a fresh // install still renders a coherent profile instead of showing a fabricated person. if (!primaryUser) { primaryUser = { id: "placeholder-user", username: "welcome", displayName: "Welcome to OpenCodeHub", email: "", bio: "Your self-hosted Git platform. Create an account to get started.", company: "", location: "", website: "", avatarUrl: "", isAdmin: false, isActive: true, emailVerified: true, twoFactorEnabled: false, twoFactorSecret: null, passwordHash: null, lastLoginAt: null, createdAt: new Date(), updatedAt: new Date(), aiConfig: null, }; } ---