Created
October 13, 2019 03:53
-
-
Save kilgarenone/dc521c015b14ee8205b4232fbdd2baf4 to your computer and use it in GitHub Desktop.
store user data to user session
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
const bcrypt = require("bcryptjs"); | |
router.post("/register", async (req, res) => { | |
const { fullName, email, password } = req.body; | |
const hashedPassword = await bcrypt.hash(password, 8); | |
const query = `INSERT INTO account(fullname, email, password) VALUES ($1, $2, $3) RETURNING user_id, fullname, email`; | |
const values = [fullName, email, hashedPassword]; | |
const { rows } = await db.query(query, values); | |
// STORING STUFF TO 'req.session' TO TELL US THIS USER STILL LOGGEDIN | |
req.session.isLoggedIn = true; | |
// AND WE STORE USER PROFILE DATA TOO | |
req.session.user = rows[0]; | |
res.status(200).send(rows[0]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment