Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = function (vars) {
- const db = vars.db;
- const JwtOptions = require('../config/jwt_options');
- const jwt = require("jwt-simple");
- return {
- authorize: function(req) {
- if (!req.cookies.username || !req.cookies.token) {
- return false;
- } else {
- var decodeToken = jwt.decode(req.cookies.token, JwtOptions.secretOrKey);
- return db.users.findById(decodeToken.id).then(function (data) {
- return data;
- }).catch(function (err) {
- console.log('authorize error: ' + err);
- return err;
- });
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement