authorization.js 481 B

1234567891011121314151617181920212223242526
  1. const UserRepository = require("../database").Repositories.Users;
  2. class Authorization {
  3. constructor() {
  4. }
  5. _parseToken(req, res, next) {
  6. const token = req.headers.token;
  7. if(!token)return next();
  8. // console.log("Token parsing : " + token);
  9. UserRepository.getUser(token).
  10. then((user) => {
  11. req.user = user;
  12. next();
  13. }).
  14. catch((err) => {
  15. res.sendStatus(400);
  16. });
  17. }
  18. getTokenParser() {
  19. return this._parseToken;
  20. }
  21. }
  22. module.exports = new Authorization();