diff options
Diffstat (limited to '')
-rw-r--r-- | database/users.js | 18 |
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); |