unable to get user session for get request
See original GitHub issueHello Guys,
I am unable to get user session when user is logged in. For example if i want to get topics for specific user. so i need value of req.user.id on topic request. But is undefined. It looks like Bug in the code.
actions/topic.js
export function fetchTopics() { return { type: types.GET_TOPICS, promise: makeTopicRequest(‘get’) }; }
app/Containers/Votes.jsx
class Vote extends Component { … static need = [ fetchTopics ] … }
server/config/routes.js
app.get(‘/topic’, topicController.all);
server/controllers/topics.js
export function all(req, res) { console.log(req.user); // undefined Topic.find({}).exec((err, topics) => { if (err) { console.log(‘Error in first query’); return res.status(500).send(‘Something went wrong getting the data’); }
return res.json(topics);
}); }
Any Solution?
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (7 by maintainers)
Top GitHub Comments
@jrodl3r you are right. Because currently i have to do hack fix to have GET while pushing to other route. We need to refactor this GET to have all the functions working properly as many people are posting in one or other thread.
@choonkending something is planned?
don’t really understand #225 too well. However, certainly think the current GET solution is not sufficient. It feels so black-box, no handlers for Success/Failure (like POST has)… would be really nice to use fetch() onEnter/onLeave for routes, but the promise fires the db-controller twice… No idea why, but having access to GET on route-handlers would be nice. Also, would be able to decrypt fetched-response if there was a Success action/callback…