Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG Lost session and some other vars in request #4541

Open
westtrade opened this issue Oct 26, 2018 · 4 comments
Open

BUG Lost session and some other vars in request #4541

westtrade opened this issue Oct 26, 2018 · 4 comments
Labels
question repro please Could you reproduce this in a repository for us?

Comments

@westtrade
Copy link

westtrade commented Oct 26, 2018

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

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

	'/': (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

@sailsbot
Copy link

Hi @westtrade! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:

  • Provide your Operating system
  • Verify "I am experiencing a concrete technical issue (aka a bug) with Sails (ideas and feature proposals should follow the guide for proposing features and enhancements (http://bit.ly/sails-feature-guide), which involves making a pull request). If you're not 100% certain whether it's a bug or not, that's okay--you may continue. The worst that can happen is that the issue will be closed and we'll point you in the right direction."
  • Verify "I am not asking a question about how to use Sails or about whether or not Sails has a certain feature (please refer to the documentation(http://sailsjs.com), or post on http://stackoverflow.com, our Google Group (http://bit.ly/sails-google-group) or our live chat (https://gitter.im/balderdashy/sails)."
  • Verify "I have already searched for related issues, and found none open (if you found a related closed issue, please link to it in your post)."
  • Verify "My issue title is concise, on-topic and polite ("jst.js being removed from layout.ejs on lift" is good; "templates dont work" or "why is sails dumb" are not so good)."
  • Verify "I have tried all the following (if relevant) and my issue remains:"
  • Verify "I can provide steps to reproduce this issue that others can follow."

As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

@westtrade westtrade changed the title Lost session and some other vars in request BUG Lost session and some other vars in request Oct 26, 2018
@johnabrams7
Copy link
Contributor

johnabrams7 commented Oct 26, 2018

@westtrade Are you getting any specific error messages or no errors during these lost requests? Also, could you provide further detail of what you are wanting to accomplish with this code? Thanks for the code examples, any more details of the project circumstances will help the community provide the best solutions and potential updates.

@westtrade
Copy link
Author

westtrade commented Oct 26, 2018

@johnabrams7 I had errors with passport.js because in first two examples variable req.user was undefined, and it break template.

Request is not lost) Variables - session, user and some other in request dying (or may be not setted) somewhere before police function (from my example) was called.

I think object request in this three cases must be identical, and don't lose any variables.

I forgot - code of FrontController.testPage

controllers/FrontController.js

module.exports = {
	async testPage(req, res) {
		res.view('pages/homepage')
	},
}
  • this case works correct

For the clarity i moved this examples into new clean project, created with

sails new test

command, and then create this issue

@mikermcneil
Copy link
Member

@westtrade I think you're right about the other issue you linked to. My guess is that this is related to Passport, but without being able to reproduce it, I can't be 100% sure. I tried what you posted initially (without passport) and couldn't reproduce an issue.

If you're seeing this issue without Passport, would you create a repo with a new Sails app (without Passport installed) that demonstrates it?

Thank you!

@mikermcneil mikermcneil added the repro please Could you reproduce this in a repository for us? label Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question repro please Could you reproduce this in a repository for us?
Development

No branches or pull requests

4 participants