0

I have an express app to handle user authentication. My app.js file has app.use("/", indexRouter); app.use("/signup", signupRouter); app.use("/login", indexRouter); the signupRouter works perfect other than when I check if sign up successful and if not re render the signup page. Basically the css goes missing.

router.get("/", function(req, res) {
  res.render("signup", { message: "Fill out the form" });
});

router.post("/register", function(req, res) {
  db.createUser(email, name, password)
    .then(function() {
      res.redirect("/");
    })
    .catch(function(err) {
      console.log("something went wrong");
      res.render("signup", { message: `something went wrong ${err}` }); 
// here css goes missing even though my public folder is set to static.
    });
});

I have an indexRouter that is:

router.get("/", function(req, res) {
  res.render("login", { message: "Enter Credentials" });
});
router.post("/login", function(req, res) {
  db.findUser(email.password)
    .then(function() {
      res.redirect("/dashboard");
    })
    .catch(function(err) {
      res.render("login", { message: "USER/PASSWORD NOT FOUND" });
    });
});

Upon hitting this /login I get 500/400 errors. How come? My setup for both routers are identical.

sakib11
  • 496
  • 1
  • 5
  • 20

1 Answers1

1

Looks like some syntax error.
In the indexRouter at line db.findUser(email.password), email.password seems the culprit.

Shouldn't it be db.findUser(email, password)

Sunil Chaudhary
  • 4,481
  • 3
  • 22
  • 41
  • yes. My god I missed it. But what about the css issue. Thanks though. – sakib11 Dec 08 '19 at 09:39
  • For that, need to see the UI code how you are trying to import the css. If it is through link tag, then we need to see if the link is getting removed or if any other the component importing the css has some issues – Sunil Chaudhary Dec 08 '19 at 09:56
  • yes link tags. It is very weird because for the first case at /register it loads fine. But for the next case when I try to render, it's gone. Any other component as in? because for login section it works fine. – sakib11 Dec 08 '19 at 10:02
  • When you try to render next case (missing css one), is the link tag for css present in your index.html? basically want to know if link tag goes missing or link tag is there but css is not getting applied – Sunil Chaudhary Dec 08 '19 at 10:05
  • yes they are present. It is probably something to do with static file setup but even that does not make sense. – sakib11 Dec 08 '19 at 10:17