bradtraversy / storybooks

Node.js app with Google OAuth
MIT License
569 stars 891 forks source link

TypeError: Cannot read property '_id' of undefined #33

Open real-zit opened 3 years ago

real-zit commented 3 years ago

TypeError: Cannot read property '_id' of undefined in global variable id is not found in the helpers editIcon function

randomartlover commented 2 years ago

TypeError: Cannot read property '_id' of undefined in global variable id is not found in the helpers editIcon function

What view did you have this error?

Ensure you have the middleware in app.js file

app.use((req, res, next)=> { res.locals.user = req.user || null; next() })

Also, ensure all queries to MongoDB is async with await. I forgot to put await when using async and it gave me the same error you have

Satya-N commented 2 years ago

TypeError: Cannot read property '_id' of undefined in global variable id is not found in the helpers editIcon function

TypeError: Cannot read property '_id' of undefined in global variable id is not found in the helpers editIcon function

What view did you have this error?

Ensure you have the middleware in app.js file

app.use((req, res, next)=> { res.locals.user = req.user || null; next() })

Also, ensure all queries to MongoDB is async with await. I forgot to put await when using async and it gave me the same error you have

the public story view file is showing the error already used the app.use((req, res, next)=> { res.locals.user = req.user || null; next() }) in app.js file

yashowardhan01 commented 2 years ago

Any solutions?