import { AuthService } from './auth.js' import { PostgresAuthRepository } from './postgres.js' const databaseUrl = process.env.DATABASE_URL if (!databaseUrl) throw new Error('DATABASE_URL is required') const repository = new PostgresAuthRepository(databaseUrl) const auth = new AuthService(repository, { sessionTtlHours: Number(process.env.SESSION_TTL_HOURS || 168), passwordPepper: process.env.AUTH_PASSWORD_PEPPER || 'development-only-pepper', }) await auth.ensureAdmin( process.env.ADMIN_ACCOUNT || 'admin@moyi.local', requiredEnvironment('ADMIN_PASSWORD'), process.env.ADMIN_DISPLAY_NAME || '平台管理员', ) await repository.close() console.log(`Admin account ensured: ${process.env.ADMIN_ACCOUNT || 'admin@moyi.local'}`) function requiredEnvironment(name: string) { const value = process.env[name] if (!value || value.startsWith('replace-with-')) throw new Error(`${name} must be set to a non-placeholder value`) return value }