Home > Back-end >  Automatic routing in expressjs
Automatic routing in expressjs

Time:01-21

I am trying to make a login form but there is a problem.The system is;If a user exists with that password and email;System is going to store the email value and password value as session.After that I want the system route user to /searchpage.

how can i do this ?

app.post("/Logincheck",function(req,res){

    var route;

    var login_email_input=req.body.email_input;

    var login_password_input=req.body.password_input;


    var query="SELECT COUNT(*) FROM users WHERE Email_value='emailx' AND Password='passwordx'";

    var query_2=query.replace("emailx",login_email_input);

    var query_3=query_2.replace("passwordx",login_password_input);


    server.query(query_3,function(error,fields,result){

        if(error){

            throw error;
        }


        else{

            var row=result[0]["COUNT(*)"];


            if(row==0){

                res.send("<script>alert('The user is not found.Please try again.')</script>");
            }


            else{

                var sess=req.session;

                session.email=login_email_input;

                session.password=login_password_input;

                route="/searchpage";
            }
        }

CodePudding user response:

You can use the method : res.redirect(route) to route the user to the Searchpage after a successful login

  • Related