diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-12-07 03:24:42 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-12-07 03:24:46 +0900 |
| commit | 26df54a09d7e195d0e33266e0b34f8e11d072277 (patch) | |
| tree | ca7f47d8beb4fcea7419350852b845b8a3179ec1 /src/server/scripts | |
| parent | 39deb471d976d863d2ec803f908025a2366f1486 (diff) | |
| download | kioku-26df54a09d7e195d0e33266e0b34f8e11d072277.tar.gz kioku-26df54a09d7e195d0e33266e0b34f8e11d072277.tar.zst kioku-26df54a09d7e195d0e33266e0b34f8e11d072277.zip | |
feat(client): remove registration page
Diffstat (limited to 'src/server/scripts')
| -rw-r--r-- | src/server/scripts/add-user.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/server/scripts/add-user.ts b/src/server/scripts/add-user.ts new file mode 100644 index 0000000..5fcccac --- /dev/null +++ b/src/server/scripts/add-user.ts @@ -0,0 +1,48 @@ +import * as readline from "node:readline/promises"; +import * as argon2 from "argon2"; +import { userRepository } from "../repositories/index.js"; + +async function main() { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + }); + + const username = await rl.question("Username: "); + const password = await rl.question("Password: "); + rl.close(); + + if (!username || !password) { + console.error("Error: Username and password are required"); + process.exit(1); + } + + if (password.length < 8) { + console.error("Error: Password must be at least 8 characters"); + process.exit(1); + } + + // Check if username already exists + const exists = await userRepository.existsByUsername(username); + if (exists) { + console.error(`Error: Username "${username}" already exists`); + process.exit(1); + } + + // Hash password with Argon2 + const passwordHash = await argon2.hash(password); + + // Create user + const newUser = await userRepository.create({ username, passwordHash }); + + console.log(`User created successfully:`); + console.log(` ID: ${newUser.id}`); + console.log(` Username: ${newUser.username}`); + + process.exit(0); +} + +main().catch((error) => { + console.error("Error:", error.message); + process.exit(1); +}); |
