question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compatibility with Sails

See original GitHub issue

I love this repository and I’m trying to use it in a Sails project.

Express middleware in sails as known as policies and internally sails use express 3.x.

Simply you can define a policies and decide what route request pass for each policies (if is necessary).

The interface for create the policy is the same to create a middleware:

module.exports = function(req, res, next) {
 // do something
};

I want to validate the header token with express-jwt and later do a custom action in the policy (for example, search the user and expose in req.user) I’m not sure how to concatenate the middlewares to get in the more external middleware the callback of the express-jwt.

Just something like this:

var options = {secret: 'seeeecret!'};
var expressjwt = require('express-jwt')({options});

module.exports = function(req, res, next) {
  expressjwt(req, res, function(token){
    // Now I have the token
    // do something
    next();
  });
};

Do you think that is possible?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Kikobeatscommented, Feb 3, 2015

Thanks!!! works perfect. Actually jsonwebtoken library validate the token, so token parameter is undefined. This works fine:

module.exports = function(req, res, next) {
  return expressjwt(req, res, function(err) {
    if (!err) {
      return next();
    }
    res.status(err.status);
    return res.json(err.inner);
  });
};

so, finally, what about add this in the documentation for future users? 😃

0reactions
jfromaniellocommented, Mar 6, 2015

I can not determine a use case where you intend to use a JSON… all time you are passing a token string, right?

no, you can create JWTs where the payload is a JSON, like this:

var jwt = require('jsonwebtoken');
var token = jwt.sign({foo: 'bar'}, secret);

in fact most of the time we use this instead of string.

I’ve fixed this on version v1.3.1.

Please next time create another issue, this issue has been closed already.

Thanks for reporting it

Read more comments on GitHub >

github_iconTop Results From Across the Web

FAQ | Sails.js
We regularly send security/compatibility reports about dependencies to the primary email address associated with your account. If you'd like additional ...
Read more >
balderdashy/sails: Realtime MVC Framework for Node.js
Compatibility. Sails is built on Node.js, Express, and Socket.io. Sails actions are compatible with Connect middleware, so in most cases ...
Read more >
sails - npm
API-driven framework for building realtime apps, using MVC conventions (based on Express and Socket.io). Latest version: 1.5.3, ...
Read more >
sails | Yarn - Package Manager
Sails.js · Installation · Your First Sails Project · Compatibility · Tutorial Course · Books · Support · Issue Submission · Contribute.
Read more >
Sails.js adapter compatibility issue in sails 1.0 - Stack Overflow
The adapter used by the sailsElastic datastore is not compatible with the current version of Sails/Waterline. The adapter should expose a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found