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 when resetting session where cookie is an object #49

Closed
Fyrebox opened this issue Jun 25, 2013 · 3 comments
Closed

Bug when resetting session where cookie is an object #49

Fyrebox opened this issue Jun 25, 2013 · 3 comments

Comments

@Fyrebox
Copy link

Fyrebox commented Jun 25, 2013

Hi
I am using Passport.js and Google Auth along with node-client-sessions to handle users' session. Everything is working quite well but when I try to reset the session, I get the error:

TypeError: Object { uid: 'AItOawmNEye27rYg8ginQ5vgZG8Gfd1sjvCqr_o',
ref: 'str',
_id: 51c924289782944904000001 } has no method 'reset']

In my cookie, I am storing the user if and a string called 'ref'. Any idea where it might come from and how to fix it ?
Cheers

@seanmonstar
Copy link
Contributor

Likely, somewhere in the code, the session object is being set to something that isn't a client-sessions session.

Likely somewhere, this is happening: req.session = someOtherObject; If someOtherObject doesn't have a reset method, then that's why you get that error.

@seanmonstar
Copy link
Contributor

We could do some things to try to handle this better:

  1. We could use Object.defineProperty() to make the property read only. That way, an error will be thrown right when people try to change the value, since quietly doing nothing means that the sessions just stop working.

  2. We could also try to be clever with Object.defineProperty() to define a getter/setter. I expect it would most often occur like this:

    req.session = { user: foo@bar.com, registered: true };

    In that case, it may be helpful to in a setter to iterate over the object and assign each property to the real session object. The downside, is that this could be too clever. Especially if it is assumed that the object assigned will still have methods from it's prototype. Maybe it's best just to error.

@Fyrebox
Copy link
Author

Fyrebox commented Jun 26, 2013

Thanks a lot for your prompt response. I actually was using connect's built-in session along with client-sessions because I needed it with Passport.js. that was the problem. Unfortunately I had to stop using client-sessions to handle OpenId sign up and sign in. Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants