I cant get the data back

Viewed 20

i have problem with my ejs i cant find it ..am trying get single email that i register on so pleas can someone help my i spend 2week with this error

my node.js code

app.use(express.static("public"));
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: true }));

const userSchema = {
  email: String,
  password: String,
};
const movies = new mongoose.model("movies", userSchema);
app.post("/login", function (req, res) {
  const username = req.body.username;
  const password = req.body.password;
  movies.findOne(
    {
      email: username,
    },
    function (err, foundUser) {
      if (err) {
        console.log(err);
      } else {
        if (foundUser) {
          if (foundUser.password === password) {
            res.render("secrets", {
              email:movies.name, password:movies.password,
            });
          }
        }
      }
    }
  );
});

//port
app.listen("3000", function () {
  console.log("server is running on port 3000");
});

my secrets page : am try to show my data

<%- include('partials/header') %>
  <div>
  <tr>
    <th scope="row"><%= movies._id %></th>
    <td><%= movies.email %></td>
    <td><%= movies.passwrd %></td>
  </tr>
</div>
<%- include('partials/footer') %>

output : in the terminal

    14|   </div>
    15|   <tr>
 >> 16|     <th scope="row"><%= movies._id %></th>
    17|     <td><%= movies.email %></td>
    18|     <td><%= movies.passwrd %></td>
    19|   </tr>

movies is not defined
1 Answers

Try to return the found value in the render statement:

if (foundUser && foundUser.password === password) {
    res.render('secrets', { movies: foundUser });
}
Related