summaryrefslogtreecommitdiff
path: root/database/users.js
diff options
context:
space:
mode:
authorJulien Dessaux2022-11-22 22:55:36 +0100
committerJulien Dessaux2022-11-22 22:55:36 +0100
commit038c877aed55cffdb4401a4c7e7b15b113798145 (patch)
treee2902779e76ba8bd60b63be0e512a3c112530d68 /database/users.js
parentAdded basic games handling (diff)
downloadjeux-de-mots-038c877aed55cffdb4401a4c7e7b15b113798145.tar.gz
jeux-de-mots-038c877aed55cffdb4401a4c7e7b15b113798145.tar.bz2
jeux-de-mots-038c877aed55cffdb4401a4c7e7b15b113798145.zip
Implemented game creation
Diffstat (limited to 'database/users.js')
-rw-r--r--database/users.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/database/users.js b/database/users.js
index 4b534b8..b24e3b4 100644
--- a/database/users.js
+++ b/database/users.js
@@ -5,13 +5,24 @@ import db from "./db.js";
const saltRounds = 10;
const createUserStatement = db.prepare("INSERT INTO users (username, hash, email) VALUES (?, ?, ?);");
-const loginStatement = db.prepare("SELECT id, hash, email FROM users WHERE username = ?;");
+const getUserByUsernameStatement = db.prepare("SELECT id, username, email from users WHERE username = ?;");
+const loginStatement = db.prepare("SELECT id, username, hash, email FROM users WHERE username = ?;");
export async function createUser(username, password, email) {
const hash = await bcrypt.hash(password, saltRounds);
try {
return createUserStatement.run(username, hash, email).lastInsertRowid;
- } catch {
+ } catch (err) {
+ console.log(err);
+ return null;
+ }
+}
+
+export function getUserByUsername(username) {
+ try {
+ return getUserByUsernameStatement.get(username);
+ } catch (err) {
+ console.log(err);
return null;
}
}
@@ -19,7 +30,8 @@ export async function createUser(username, password, email) {
export async function login(username, password) {
try {
var user = loginStatement.get(username);
- } catch {
+ } catch (err) {
+ console.log(err);
return null;
}
const result = await bcrypt.compare(password, user.hash);