How do I render the Users page to the authenticated User

Viewed 17

I am buildind this webapp and I want the User to be able to login and see his or her activities. But then when a new User signs up they see the activity of the other users. But that is not what i want, I want every user to be able to see his or her own activity.

I am using passports local strategy for authentication and mongoose for the database.

app.get("/list", function (req, res) {
  if (req.isAuthenticated()) {
    User.find({id : req.user.id}, function (err, foundUsers) {
      if (!foundUsers.list) {
        User.insertMany(defaultItems, function (err) {
          if (err) {
            console.log(err);
          } else {
            console.log("Successfully saved default items to DB");
          }
        });
        res.redirect("/list");
      } else {
        res.render("index", {
          kindOfDay: today,
          newListItems: foundUsers.list
        });
      }
    });
  } else {
    res.redirect("/login");
  }
});

When the user goes into the list page he should be able to see only his or her created lists

0 Answers
Related