Advertisement
kuznets

authorize.v1.1.js

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