forked from RiskyMH/EmailThing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-admin.ts
42 lines (34 loc) · 997 Bytes
/
create-admin.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
33
34
35
36
37
38
39
40
41
42
import { Mailbox, MailboxAlias, MailboxForUser, User, db } from "@/db";
import { createPasswordHash } from "@/utils/password";
import { createId } from "@paralleldrive/cuid2";
const username = prompt("Enter username:");
const password = prompt("Enter password:");
if (!(username && password)) {
console.log("Username and password are required");
process.exit(1);
}
const userId = createId();
const mailboxId = createId();
await db.batch([
db.insert(User).values({
id: userId,
username,
password: await createPasswordHash(password),
email: `${username}@emailthing.xyz`,
admin: true,
}),
db.insert(Mailbox).values({
id: mailboxId,
}),
db.insert(MailboxForUser).values({
mailboxId,
userId,
}),
db.insert(MailboxAlias).values({
mailboxId,
alias: `${username}@emailthing.xyz`,
default: true,
name: username,
}),
]);
console.log("User created successfully");