londonappbrewery / Authentication-Secrets

Companion Code for the Authentication Module on The Complete 2019 Web Development Bootcamp
https://www.appbrewery.co
440 stars 524 forks source link

It doesnt appear the secrets! #3

Open ezeloop opened 4 years ago

ezeloop commented 4 years ago

I have all the code like the posted one, and it doesnt appear the secrets!

app.get("/secrets", function(req, res){ User.find({"secret": {$ne: null}}, function(err, foundUsers){ if (err){ console.log(err); } else { if (foundUsers) { res.render("secrets", {usersWithSecrets: foundUsers}); } } }); });

in the db i have the secret, but i cant show them!

hadihammad commented 4 years ago

you need to edit secrets.ejs

0514sm commented 4 years ago

edit secrets.ejs with <% usersWithSecrets.forEach(function(ele){ %>

<%= ele.secret%>

<%} %>

jkalandarov commented 4 years ago

Same problem with me. First of all, it is not saving input (secret) into DB, that's why it is not rendering secrets. I copied the code from here, but no change. Tried restarting DB and so on. Any idea why?

kostiastrong commented 4 years ago

I copied the code from here, but no change. Tried restarting DB and so on. Any idea why?

I guess you forgot to add submit post route:

app.post("/submit", function(req, res) {
  const submittedSecret = req.body.secret;

  User.findById(req.user.id, function(err, foundUser) {
    if (err) {
      console.log(err);
    } else {
      if (foundUser) {
        foundUser.secret = submittedSecret;
        foundUser.save(function() {
          res.redirect("/secrets");
        });
      }
    }
  });
});
harshptl176 commented 4 years ago

Have you update your user schema i.e add secrets: String in user schema?

Webbuster99 commented 2 years ago

I am updated the userschema & also added the submit post route code but it's still not working.. how can I fix this secret route problem that can loop through all my secrets ??? plz help me

mohitverma-2010 commented 2 years ago

req.user._id

Use this in submit post request, it will work!

faizalkhan99 commented 2 years ago

req.user._id

Use this in submit post request, it will work!

Hey! I tried all of the things but none worked for me:( my code is exactly the same as Angela.

shahkashif96 commented 2 years ago

Hey!! did u manage to solve the issue? I am facing exactly the same issue. But i have an extra issue.. my secret isnt even getting saved in the db.

SKSALI1 commented 1 year ago

it is deprecated, and dont know how to write them now