-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddUser.ts
32 lines (26 loc) · 860 Bytes
/
addUser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// addUser.js
import { db } from './src/lib/server/db/index.ts'; // Adjust path if needed
import { user } from './src/lib/server/db/schema.ts';
import bcrypt from 'bcrypt';
async function addUser(username, password) {
// Hash the password
const passwordHash = await bcrypt.hash(password, 10);
// Insert the user into the database
await db.insert(user).values({
id: crypto.randomUUID(), // Generate a unique ID
username,
passwordHash,
}).execute();
console.log(`User ${username} added successfully!`);
}
// Capture command-line arguments
const [username, password] = process.argv.slice(2);
if (!username || !password) {
console.error("Usage: node addUser.js <username> <password>");
process.exit(1);
}
addUser(username, password)
.catch((error) => {
console.error("Error adding user:", error);
process.exit(1);
});