Yess. I already have an AuthContext.Provider in App.js and I imported it
<div className="App"> <AuthContext.Provider value={{ authState, setAuthState }}> <Router> <Header /> <Routes> <Route exact path="/" element={<Mainpage />} /> <Route exact path="/login" element={<Login />} /> <Route exact path="/register" element={<Register />} /> <Route path="/profile" element={<Profile />} /> <Route path="/courses" /> </Routes> </Router> </AuthContext.Provider> </div>
app.get is just returning req.session.user. I created it in app.post('/login'). Here it is
app.post("/login", (req, res) => { const email = req.body.email; const password = req.body.password; db.query("SELECT * FROM users WHERE email = ?;", email, (err, result) => { if (err) { res.send({ err: err }); } if (result.length > 0) { bcrypt.compare(password, result[0].password, (error, response) => { if (response) { req.session.user = result; // console.log("hello: " + req.session.user); res.send(result); } else { res.send({ message: "Wrong username/password combination!" }); } }); } else { res.send({ message: "User doesn't exist" }); } }); });
Thank you for the tips and the sources. I will check immediately
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yess. I already have an AuthContext.Provider in App.js and I imported it
app.get is just returning req.session.user. I created it in app.post('/login'). Here it is
Thank you for the tips and the sources. I will check immediately