From 1a410a597a499f1ed9d589930e489910f8525329 Mon Sep 17 00:00:00 2001 From: knotteye Date: Tue, 13 Oct 2020 16:29:13 -0500 Subject: [PATCH] Fix a bug checking the validity of invite codes --- src/http.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/http.ts b/src/http.ts index 0c0aa6b..8eb06dc 100644 --- a/src/http.ts +++ b/src/http.ts @@ -225,18 +225,20 @@ async function initAPI() { }); app.post('/api/register', (req, res) => { if("invite" in req.body){ - if(api.validInvite(req.body.invite)){ - api.register(req.body.username, req.body.password, req.body.confirm, true).then((result) => { - if(result[0]) return genToken(req.body.username).then((t) => { - res.cookie('Authorization', t, {maxAge: 604800000, httpOnly: true, sameSite: 'Lax'}); + api.validInvite(req.body.invite).then((v) => { + if(v){ + api.register(req.body.username, req.body.password, req.body.confirm, true).then((result) => { + if(result[0]) return genToken(req.body.username).then((t) => { + res.cookie('Authorization', t, {maxAge: 604800000, httpOnly: true, sameSite: 'Lax'}); + res.json(result); + api.useInvite(req.body.invite); + return; + }); res.json(result); - api.useInvite(req.body.invite); - return; }); - res.json(result); - }); - } - else res.json({error: "invalid invite code"}); + } + else res.json({error: "invalid invite code"}); + }); } else api.register(req.body.username, req.body.password, req.body.confirm).then( (result) => {