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.

Cannot change `requestProperty` object.

See original GitHub issue

Cannot seem to change the requestProperty of my user object to payload. Double checked req.payload and its working fine without the guard.

Here’s my express-JWT config:

let auth = {
    required: jwt({
        secret: secret,
        userProperty: 'payload',
        getToken: getTokenFromHeader
    })
}

signing jwt

    return jwt.sign({
      id: this._id,
      username: this.username,
      exp: parseInt(exp.getTime() / 1000),
      permissions: ['r','w']
    }, secret);

Set using let guard = require('express-jwt-permissions')({requestProperty: 'payload'}); Accessing it using guard.check('r') throws 'user object payload was not found. Check your configuration.'

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MichielDeMeycommented, Jul 23, 2018

Glad you found the problem. 👍

0reactions
kvrtingcommented, Jul 23, 2018

I’ve found the cause of the problem. Given my code:

const jwt = require('express-jwt');

let auth = {
    required: jwt({
        secret: secret,
        requestProperty: 'payload',
        getToken: getTokenFromHeader
    }),
    optional: jwt({
        ....
    })
};

Calling guard.check() first before an express-jwt rule results to not passing the request object properly. router.get('/foo', guard.check('root'), auth.required, function (req, res, next) {...} is fixed with router.get('/foo', auth.required, guard.check('root'),function (req, res, next) {...}

Overlooked this simple mistake. Thanks for the quick response!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modify the URL of a new Request Object in ES6 - Stack Overflow
You can copy all the properties from the old request into a new one with a new url like so: const init =...
Read more >
TypeError: can't define property "x": "obj" is not extensible
To fix this error, you will either need to remove the call to Object.preventExtensions() entirely, or move it to a position so that...
Read more >
Modify request objects within middleware function #31188
One thing I've been unable to figure out is modifying request objects within a middleware. Is this currently possible?
Read more >
Change Preprocessors - FileNet P8 - IBM
The source object in a create, update, or delete server request is passed to a change preprocessor handler. The source object includes a...
Read more >
Re: Cannot change object of property - HubSpot Community
Hi , The object of a property cannot be changed after its creation. You would have to create a new one. Properties that...
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