Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. module.exports = function (vars) {
  2. const db = vars.db;
  3. const JwtOptions = require('../config/jwt_options');
  4. const jwt = require("jwt-simple");
  5.  
  6. return {
  7. authorize: function(req) {
  8. if (!req.cookies.username || !req.cookies.token) {
  9. return false;
  10. } else {
  11. var decodeToken = jwt.decode(req.cookies.token, JwtOptions.secretOrKey);
  12.  
  13. return db.users.findById(decodeToken.id).then(function (data) {
  14. return data;
  15. }).catch(function (err) {
  16. console.log('authorize error: ' + err);
  17. return err;
  18. });
  19. }
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement