chore: 准备后端开源安全状态
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
import { PrismaClient, UserRole, UserStatus } from '@prisma/client';
|
||||
import {
|
||||
SUPER_ADMIN_INITIAL_PASSWORD,
|
||||
SUPER_ADMIN_SEED,
|
||||
} from './auth.constants';
|
||||
import { SUPER_ADMIN_SEED } from './auth.constants';
|
||||
import { PasswordService } from './password.service';
|
||||
|
||||
loadProductionEnv();
|
||||
@@ -14,19 +11,14 @@ const passwordService = new PasswordService();
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const configuredPassword = process.env.SUPER_ADMIN_RESET_PASSWORD?.trim();
|
||||
const password =
|
||||
configuredPassword ||
|
||||
(process.env.NODE_ENV === 'production'
|
||||
? undefined
|
||||
: SUPER_ADMIN_INITIAL_PASSWORD);
|
||||
|
||||
if (!password) {
|
||||
if (!configuredPassword) {
|
||||
throw new Error(
|
||||
'生产环境缺少 SUPER_ADMIN_RESET_PASSWORD,不能使用公开默认密码重置超级管理员',
|
||||
'缺少 SUPER_ADMIN_RESET_PASSWORD,不能重置超级管理员密码',
|
||||
);
|
||||
}
|
||||
|
||||
const passwordHash = await passwordService.hashPassword(password);
|
||||
const passwordHash = await passwordService.hashPassword(configuredPassword);
|
||||
|
||||
await prisma.user.upsert({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user