Skip to content

Commit

Permalink
backend
Browse files Browse the repository at this point in the history
  • Loading branch information
theabbie committed Sep 26, 2021
1 parent 9e77953 commit 6f115c5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pages/api/getToken.js
Expand Up @@ -17,7 +17,16 @@ export default async function handler(req, res) {
}
else {
var user = await client.query("INSERT INTO USERS (PUBLIC_KEY, NONCE) VALUES ($1, $2) RETURNING NONCE", [public_key, crypto.randomBytes(8).toString('hex')]);
res.json(user);
if (user.rows.length > 0) {
res.json(user.rows[0]);
return;
}
else {
res.writeHead(302, {
Location: "/",
});
res.end();
}
}
} catch (e) {
console.log(e);
Expand Down

0 comments on commit 6f115c5

Please sign in to comment.