balderdashy / balderdashy/sails

BUG Lost session and some other vars in request

Open
#4,541 4 comments 0 reactions 0 assignees View on GitHub
question repro please
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Sails version**: v1.0.2
**Node version**: v10.8.0
**NPM version**: 6.2.0
**DB adapter name**: N/A
**DB adapter version**: N/A
**Operating system**: Linux 4.15.0-38-generic #41-Ubuntu SMP Wed Oct 10 10:59:38 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux


I have simple function defined in config/police.js

```js

module.exports.policies = {
'*': [
(req, res, next) => {
console.log('Session in police', req.session)
console.log(new Error().stack)
next()
},
],
}

```

And three test routes in config/routes.js

```js
'/': (req, res) => {
//req.session - exists
res.view('pages/homepage') // <- in template req.session is undefined
}, //<-- req.session in police middleware is undefined, and lost other custom variables assigned to req (such as req.user defined by passport.js)
// and code in police run after
'/testview': {
view: 'pages/homepage',
}, //<-- req.session is undefined
'/test-1': 'FrontController.testPage', //<-- in this case alright

```

this code produce bug with lost request variables, such as session, user and other

I think this issue maybe related to #4427

Contributor guide

Open the contributing guide

Research direction

Start with config/police.js and config/routes.js, then reproduce the three routes while logging req.session and other request variables in the policy, route handler, and rendered view. Compare the affected view routes with /test-1 and verify that session, user, and other custom request variables remain available throughout the request.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.