0

the error part pageReferenceError: res is not defined

I am just rendering the dashboard page after successfull login but even though credentials are correct , i am still not able to see dashboard page . Here my server.js file code! app.post("/login",async(req,res)=>{ try{ const email = req.body.fromemail; const password = req.body.password; const useremail = await User.findOne({email:email}); const isMatch = await bcrypt.compare(password,useremail.password); console.log(isMatch); const token = await useremail.generateAuthToken(); console.log("the token part"+token); if (isMatch){ res.status(201).render("dash"); } else{ res.send("invalid login details"); } // res.send(userstatus.password) // console.log(userstatus.password); // // console.log(email+" and "+password); // res.render("dash"); }catch(err){ console.log("the error part page"+err); res.status(400).send("invalid"); } // res.render("dash"); })

13th Nov 2022, 10:37 AM
Abhinav Gourav Simhadri
Abhinav Gourav Simhadri - avatar
3 Antworten
+ 2
You got error because you are using res intend of response so you should call it like that 👇 const res = require('express/lib/response')
22nd Nov 2022, 5:50 AM
Félix Zamdamela
Félix  Zamdamela - avatar
+ 2
Yes but past the variable res near where you are set modules variables Ex. const express = require('express'); const res = require ('express/lib/response') // to tell the playground that you are using 'response' on your parameters on app.post('login', (req, res)=>{ some code... }) Because some playground don't recognize the abbreviation key words
22nd Nov 2022, 7:29 AM
Félix Zamdamela
Félix  Zamdamela - avatar
0
I have already passed it as parameter
22nd Nov 2022, 7:15 AM
Abhinav Gourav Simhadri
Abhinav Gourav Simhadri - avatar