aboutsummaryrefslogtreecommitdiff
path: root/scripts/gen-invite.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gen-invite.js')
-rw-r--r--scripts/gen-invite.js4
1 files changed, 0 insertions, 4 deletions
diff --git a/scripts/gen-invite.js b/scripts/gen-invite.js
index 0c6a808..3336a83 100644
--- a/scripts/gen-invite.js
+++ b/scripts/gen-invite.js
@@ -4,7 +4,6 @@ const db = new Database("readit.db", {
4 strict: true, 4 strict: true,
5}); 5});
6 6
7// Create the invites table if it doesn't exist
8db.run(` 7db.run(`
9 CREATE TABLE IF NOT EXISTS invites ( 8 CREATE TABLE IF NOT EXISTS invites (
10 id INTEGER PRIMARY KEY AUTOINCREMENT, 9 id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -14,20 +13,17 @@ db.run(`
14 ) 13 )
15`); 14`);
16 15
17// Generate a new invite token
18function generateInviteToken() { 16function generateInviteToken() {
19 const hasher = new Bun.CryptoHasher("sha256", "super-secret-invite-key"); 17 const hasher = new Bun.CryptoHasher("sha256", "super-secret-invite-key");
20 return hasher.update(Math.random().toString()).digest("hex"); 18 return hasher.update(Math.random().toString()).digest("hex");
21} 19}
22 20
23// Store the token in the database
24function createInvite() { 21function createInvite() {
25 const token = generateInviteToken(); 22 const token = generateInviteToken();
26 db.run("INSERT INTO invites (token) VALUES ($token)", { token }); 23 db.run("INSERT INTO invites (token) VALUES ($token)", { token });
27 console.log(`Invite token created: ${token}`); 24 console.log(`Invite token created: ${token}`);
28} 25}
29 26
30// CLI usage
31const command = process.argv[2]; 27const command = process.argv[2];
32const arg = process.argv[3]; 28const arg = process.argv[3];
33 29