45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { PrismaClient } from "../lib/generated/prisma";
|
|
import bcrypt from "bcryptjs";
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log("🔧 ساخت کاربر تست...\n");
|
|
|
|
const email = "test@test.com";
|
|
const password = "123456";
|
|
const hashedPassword = await bcrypt.hash(password, 10);
|
|
|
|
// حذف کاربر قبلی اگر وجود دارد
|
|
await prisma.user.deleteMany({
|
|
where: { email },
|
|
});
|
|
|
|
const user = await prisma.user.create({
|
|
data: {
|
|
email,
|
|
password: hashedPassword,
|
|
name: "کاربر تست",
|
|
role: "USER",
|
|
},
|
|
});
|
|
|
|
console.log("✅ کاربر تست ساخته شد:");
|
|
console.log(` ایمیل: ${email}`);
|
|
console.log(` رمز عبور: ${password}`);
|
|
console.log(` ID: ${user.id}`);
|
|
console.log(` نقش: ${user.role}`);
|
|
console.log("\n🔐 برای ورود از این اطلاعات استفاده کنید:");
|
|
console.log(` Email: ${email}`);
|
|
console.log(` Password: ${password}`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error("❌ خطا:", e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|