Codecademy ecommerce Group Project in The Full-Stack Engineer Path (flying solo).
0
stars
0
forks
source link
BUG: You're not authorized to view this page - Session authentication property doesn't appear on session after login even though user is successfully authenticated during login. #4
function ensureAuthentication(req, res, next) {
// Complete the if statement below:
if (req.session.authenticated) {
return next();
} else {
res.status(403).json({ msg: "You're not authorized to view this page" });
}
}
Fixed: Needed to drill down to extract the specific user object in the result.rows array element; sent within the boject of objects returned from the db to the passport LocalStrategy.
function ensureAuthentication(req, res, next) { // Complete the if statement below: if (req.session.authenticated) { return next(); } else { res.status(403).json({ msg: "You're not authorized to view this page" }); } }
//login authentication: // app.post("/login", (req, res) => { // const { email, password } = req.body.user; // if (password == "codec@demy10") { // // Attach an
authenticated
property to our session: // req.session.authenticated = true; // // Attach a user object to our session: // req.session.user = { // email, // password, // }; // res.redirect("/"); // } else { // res.send("Who dares disturb my slumber? ;<"); // } // });