Initial commit: 용산 공중케이블 주민 안전 협의회 홈페이지
- Next.js 16 App Router + TypeScript + Tailwind CSS 4 - Prisma/SQLite 기반 공지사항·자료실·관리자·문의/제보 - 네이버 블로그 RSS 최신 글 5개 노출 - OCI 운영 배포 스크립트 및 문서
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 관리자 비밀번호를 변경하거나 새 관리자 계정을 만듭니다.
|
||||
*
|
||||
* 사용법:
|
||||
* npm run admin:password -- <아이디> <새비밀번호>
|
||||
*
|
||||
* 예시:
|
||||
* npm run admin:password -- admin 'NewStrongPassword!2026'
|
||||
*/
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const [, , loginIdArg, passwordArg] = process.argv;
|
||||
const loginId = (loginIdArg ?? process.env.ADMIN_LOGIN_ID ?? "").trim();
|
||||
const password = passwordArg ?? process.env.ADMIN_NEW_PASSWORD ?? "";
|
||||
|
||||
if (!loginId) {
|
||||
console.error("아이디를 입력해 주세요. 예: npm run admin:password -- admin '새비밀번호'");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (password.length < 8) {
|
||||
console.error("비밀번호는 8자 이상이어야 합니다.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const passwordHash = await bcrypt.hash(password, 12);
|
||||
|
||||
const admin = await prisma.adminUser.upsert({
|
||||
where: { loginId },
|
||||
update: { passwordHash },
|
||||
create: {
|
||||
loginId,
|
||||
passwordHash,
|
||||
name: "홈페이지 관리자",
|
||||
role: "ADMIN",
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`관리자 계정이 준비되었습니다: ${admin.loginId} (${admin.name})`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user