ga-wdi-boston / team-project

Other
2 stars 39 forks source link

Handlebars error #393

Closed jingrid closed 7 years ago

jingrid commented 7 years ago

When trying to view all Pages before signing in, I'm getting the error:

jquery.js:3860 jQuery.Deferred exception: Cannot read property 'id' of undefined TypeError: Cannot read property 'id' of undefined

I think the issue lies in how I have handlebars set up to check for the ID of the user that's signed in, so obviously when user is not signed in, the ID will be undefined. How can I get around this?

I currently have handlebar as follows:

{{#each pages as |page|}}

<div id="all-pages-container" class="col-xs-4 box">
    <div id="all-pages-container" data-id="{{page.id}}">
      <ul name='page-name' class='handlebars-fields'>Title: <span class='handlebars' id='page-title'>{{page.title}}</span></ul>
      <ul class='handlebars-fields'>Content: <span id='page-content' class='handlebars'>{{page.content}}</span></ul>

    {{#checkUser page._owner}}

      <button type="submit" class="remove-button" name="remove-button">Remove</button>
      <button type="submit" class="edit-button" name="edit-button">Edit</button>

    {{/checkUser}}
  </div>
</div>

{{/each}}

checkUser is a helper, as follows:

const store = require('../../store')

module.exports = function (userId) {
  if (userId === store.user.id) {
    return '<button type="submit" class="remove-button" name="remove-button">Remove</button>  <button type="submit" class="edit-button" name="edit-button">Edit</button>'
  } else {
  }
}
payne-chris-r commented 7 years ago

Try this?

module.exports = function (userId) {
  if (store.user && (store.user.id === userId)) {
    return '<button type="submit" class="remove-button" name="remove-button">Remove</button>  <button type="submit" class="edit-button" name="edit-button">Edit</button>'
  } else {
  }
}
jingrid commented 7 years ago

wow amazing. thx u