diff options
author | Akshay <[email protected]> | 2024-11-15 21:25:27 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2024-11-15 21:25:27 +0000 |
commit | c5cd65eba355e66589298cbe88fe3489e0fcebae (patch) | |
tree | 4050c946c4611e88c51efbb61cc44903fca5fd82 /scripts/gen-invite.js | |
parent | d4a83cb44dc98fe78f9061408137a43049344b1d (diff) |
invalidate registered tokens properly
Diffstat (limited to 'scripts/gen-invite.js')
-rw-r--r-- | scripts/gen-invite.js | 4 |
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 | ||
8 | db.run(` | 7 | db.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 | ||
18 | function generateInviteToken() { | 16 | function 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 | ||
24 | function createInvite() { | 21 | function 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 | ||
31 | const command = process.argv[2]; | 27 | const command = process.argv[2]; |
32 | const arg = process.argv[3]; | 28 | const arg = process.argv[3]; |
33 | 29 | ||