Download src/app/actions/setup.ts from sarransh/task-manager-system: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/spaces/sarransh/task-manager-system/resolve/main/src/app/actions/setup.ts
- Command line
-
hf download hf://spaces/sarransh/task-manager-system/src/app/actions/setup.ts
-
curl -L -o setup.ts https://huggingface.co/spaces/sarransh/task-manager-system/resolve/main/src/app/actions/setup.ts
1.41 kB
| "use server"; | |
| import bcrypt from "bcryptjs"; | |
| import { prisma } from "@/lib/prisma"; | |
| export async function createAdminUser(email: string, password: string) { | |
| if (!email || !password) { | |
| return { success: false, error: "Missing email or password" }; | |
| } | |
| try { | |
| console.log(`[SETUP] Creating user: ${email}`); | |
| // 1. Check if user exists | |
| const existing = await prisma.user.findFirst({ | |
| where: { email } | |
| }); | |
| if (existing) { | |
| console.log(`[SETUP] User existing: ${existing.id}`); | |
| return { success: false, error: `User with email ${email} already exists` }; | |
| } | |
| // 2. Hash password | |
| const passwordHash = await bcrypt.hash(password, 10); | |
| console.log(`[SETUP] Hashed password: ${passwordHash.substring(0, 10)}...`); | |
| // 3. Create user | |
| const newUser = await prisma.user.create({ | |
| data: { | |
| name: "Admin User", | |
| email, | |
| passwordHash, | |
| role: "ADMIN" | |
| } | |
| }); | |
| console.log(`[SETUP] Success! User ID: ${newUser.id}`); | |
| return { success: true }; | |
| } catch (error: any) { | |
| console.error("[SETUP] Error:", error); | |
| return { | |
| success: false, | |
| error: error.message || String(error) | |
| }; | |
| } | |
| } | |