-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Added bcrypt to hash password before storing in the DB. 2. Used express json middleware to parse request body data to json object.
- Loading branch information
1 parent
7e55b5c
commit 9f34b93
Showing
5 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
const sqliteWrapper = require("../db"); | ||
const bcrypt = require("bcrypt"); | ||
const { sqliteWrapper } = require("../db"); | ||
|
||
exports.login = (req, res) => { | ||
res.status(200).json({ | ||
message: "Logging in User", | ||
}); | ||
}; | ||
|
||
exports.register = (req, res) => { | ||
res.status(200).json({ | ||
message: "Register User", | ||
}); | ||
exports.register = async (req, res) => { | ||
const { email, password } = req.body; | ||
try { | ||
const salt = await bcrypt.genSalt(); | ||
const hashedPassword = await bcrypt.hash(password, salt); | ||
|
||
const createUserQuery = `INSERT INTO users VALUES (NULL, "${email}", "${hashedPassword}")`; | ||
const method = "run"; | ||
const user = await sqliteWrapper(createUserQuery, method); | ||
res.status(200).json({ | ||
message: "Register User", | ||
user, | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
res.status(500).json({ | ||
message: "Error while registering. Please, try again", | ||
error, | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters