Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. function isAllowed(req, res, next) {
  2. let decodeToken = jwt.decode(req.cookies.token, JwtOptions.secretOrKey);
  3.  
  4. db.users.findById(decodeToken.id).then(data => {
  5. if (data == null) {
  6. throw {
  7. success: false,
  8. message: 'User token not found'
  9. }
  10. }
  11.  
  12. req.session.user = data; // hz dolzno prokinutj
  13. next();
  14. })
  15. .catch(function (err) {
  16. res.status(401).send(err.message);
  17. });
  18. }
  19.  
  20. app.get('/api/orders', isAllowed, function (req, res) {
  21. db.ordersfindAll({
  22. where: {
  23. userId: req.session.user.id
  24. }
  25. })
  26. .then(orders => res.json({message: 'OK', body: orders}));
  27. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement