1
votes

I am new in node js trying to send Alert messages on screen iF user added the wrong credentials .Problem is , It through an error that Alert isn't defined . if i send same message through res.send then it work without any error but I want to show alert can someone guide me Note : this code is written at server side file for node js this code through an error say alerts is not defined

 Router.post('/login',(req,res)=>
 {

    const{
        email,
        password
    }=req.body;
    homeschema.findOne({email:email},(err,result)=>{
        if(email==result.email && password === result.password)
        {
            res.render('activate');

            
        }
        else
        {
            alert("incorrect email/password")
        }
    })
 })

this code is working fine and send a response message perfectly

 Router.post('/login',(req,res)=>
 {

    const{
        email,
        password
    }=req.body;
    homeschema.findOne({email:email},(err,result)=>{
        if(email==result.email && password === result.password)
        {
            res.render('activate');

            
        }
        else
        {
            res.send("EMAIL/PASSWORD incorrect");
        }
    })
 })
1
You know that saving a plain text password is an security issue? - bill.gates
What kind of behavior are you looking for here? Do you want like a window.alert() message on the frontend? - cheesemas46
yes exactly i want to show email/password incorrect message on frontend - ABDULLAH Moiz

1 Answers

0
votes

Node.js is a backend framework and you cannot handle frontend alerts and popups here.
All you can do is handle alerts in the frontend based on the response you get from the backend(node.js server).
You can also make use of status codes so that it'll be easy for you to authenticate and do the next process.

Hope it helps!.