2026-10-25 06:12:47 -07:00
|
|
|
import { AdminSetup } from '@/components/sections/AdminSetup';
|
2026-11-19 20:22:01 +06:00
|
|
|
import {
|
|
|
|
|
isAdminSetupComplete,
|
|
|
|
|
requiresPersistentAdminDatabase,
|
|
|
|
|
} from '@/core/auth/adminUsers';
|
2026-10-25 06:12:47 -07:00
|
|
|
import { redirect } from 'next/navigation';
|
|
|
|
|
|
|
|
|
|
export const runtime = 'nodejs';
|
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
|
|
|
|
|
|
export default async function SetupPage() {
|
|
|
|
|
let databaseReady = true;
|
2026-11-19 20:22:01 +06:00
|
|
|
let databaseError = '';
|
|
|
|
|
let setupComplete = false;
|
|
|
|
|
|
|
|
|
|
if (requiresPersistentAdminDatabase()) {
|
2026-10-25 06:12:47 -07:00
|
|
|
databaseReady = false;
|
2026-11-19 20:22:01 +06:00
|
|
|
databaseError =
|
|
|
|
|
'PostgreSQL DATABASE_URL is required in production before creating an administrator account.';
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
setupComplete = await isAdminSetupComplete();
|
|
|
|
|
} catch {
|
|
|
|
|
databaseReady = false;
|
|
|
|
|
databaseError = 'Database connection unavailable.';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (databaseReady && setupComplete) {
|
|
|
|
|
redirect('/vcon/login');
|
2026-10-25 06:12:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<AdminSetup
|
|
|
|
|
databaseReady={databaseReady}
|
2026-11-19 20:22:01 +06:00
|
|
|
databaseError={databaseError}
|
2026-10-25 06:12:47 -07:00
|
|
|
initialEmail={process.env.DATASTACK_ADMIN_EMAIL?.trim().toLowerCase() ?? ''}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|