aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-11-15 21:25:27 +0000
committerAkshay <[email protected]>2024-11-15 21:25:27 +0000
commitc5cd65eba355e66589298cbe88fe3489e0fcebae (patch)
tree4050c946c4611e88c51efbb61cc44903fca5fd82 /src
parentd4a83cb44dc98fe78f9061408137a43049344b1d (diff)
invalidate registered tokens properly
Diffstat (limited to 'src')
-rw-r--r--src/invite.js2
-rw-r--r--src/public/styles.css1
-rw-r--r--src/routes/index.js6
3 files changed, 5 insertions, 4 deletions
diff --git a/src/invite.js b/src/invite.js
index 0f6624c..7e357ac 100644
--- a/src/invite.js
+++ b/src/invite.js
@@ -11,7 +11,7 @@ const validateInviteToken = async (req, res, next) => {
11 } 11 }
12 12
13 const invite = db 13 const invite = db
14 .query("SELECT * FROM invites WHERE token = $token AND usedAt IS null") 14 .query("SELECT * FROM invites WHERE token = $token")
15 .get({ token }); 15 .get({ token });
16 16
17 if (!invite) { 17 if (!invite) {
diff --git a/src/public/styles.css b/src/public/styles.css
index 523e81b..2f39234 100644
--- a/src/public/styles.css
+++ b/src/public/styles.css
@@ -499,6 +499,7 @@ form input[type="submit"]:hover {
499} 499}
500 500
501.register-error-message { 501.register-error-message {
502 margin-bottom: 1rem;
502 flex-flow: row wrap; 503 flex-flow: row wrap;
503 color: var(--error-text-color); 504 color: var(--error-text-color);
504} 505}
diff --git a/src/routes/index.js b/src/routes/index.js
index 8529595..6efeb79 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -20,7 +20,6 @@ router.get("/", authenticateToken, async (req, res) => {
20 res.redirect("/r/all"); 20 res.redirect("/r/all");
21 } else { 21 } else {
22 const p = subs.map((s) => s.subreddit).join("+"); 22 const p = subs.map((s) => s.subreddit).join("+");
23 console.log(p);
24 res.redirect(`/r/${p}`); 23 res.redirect(`/r/${p}`);
25 } 24 }
26}); 25});
@@ -143,7 +142,9 @@ router.post("/register", validateInviteToken, async (req, res) => {
143 try { 142 try {
144 const hashedPassword = await Bun.password.hash(password); 143 const hashedPassword = await Bun.password.hash(password);
145 144
146 db.query("UPDATE invites SET usedAt = CURRENT_TIMESTAMP WHERE id = $id", { 145 db.query(
146 "UPDATE invites SET usedAt = CURRENT_TIMESTAMP WHERE id = $id",
147 ).run({
147 id: req.invite.id, 148 id: req.invite.id,
148 }); 149 });
149 150
@@ -165,7 +166,6 @@ router.post("/register", validateInviteToken, async (req, res) => {
165 }) 166 })
166 .redirect("/"); 167 .redirect("/");
167 } catch (err) { 168 } catch (err) {
168 console.log(err);
169 return res.render("register", { 169 return res.render("register", {
170 message: "error registering user, try again later", 170 message: "error registering user, try again later",
171 }); 171 });