Handlebar Comparison Expression for userID

Handlebar Comparison Expression for userID

I need to restrict editing and deleting options on a list of events to the creators of those events only.

I managed to fetch the currentUser._id when submitting the form and save it on my mongoDB, but I now face the problem of how to compare this to the session.currentUser._id in order to match them and use them in my {{#if}} in handlebars. Does anyone have any input on how to approach this? below is my JS and hbs for reference.

router.get('/events-all', (req, res, next) => {
  res.render('events/events-all');
  });
  
  router.post('/new-event', (req, res, next) => {
      const host = req.session.currentUser._id;
      const { title, location, date, time } = req.body;
      const newEvent = new Event({ title, location, date, time, host });
      newEvent.save()
      .then(() => {
        res.redirect('events-all');
      })
      .catch((error) => {
        console.log('Error while adding event', error);
      });
    });
{{#if (host === currentUser._id) }}
<section class="cards">
  <article class="card-events">
      <h3>{{location}}</h3>
          <picture class="thumbnail">
         <img class="category__01" src="/images/citydefult.jpeg" alt="" />
    </picture>
      <h5>{{title}}</h5>
      <h6>{{date}}</h6>
      <p>Starting time: {{time}}</p>
      <a href="/events/{{id}}/edit">
          <button type="submit" class="btn btn-danger">Edit</button>
      </a> 
        <form method="POST" action="/events/{{id}}/delete">
          <button type="submit" class="btn btn-danger">Delete</button> 
        </form>
  </article>
</section>
{{else}}
<section class="cards">
  <article class="card-events">
      <h3>{{location}}</h3>
          <picture class="thumbnail">
         <img class="category__01" src="/images/citydefult.jpeg" alt="" />
    </picture>
      <h5>{{title}}</h5>
      <h6>{{date}}</h6>
      <p>Starting time: {{time}}</p>
        </form>
  </article>
</section>
{{/if}}
8
Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.