Giter Site home page Giter Site logo

Comments (17)

alvarotrigo avatar alvarotrigo commented on April 25, 2024 3

Sometimes I wonder how is it possible these modules get downloaded 70K times a month and their documentation and support is so limited.

I might be used to other platforms where things are different... but Node never stops surprising me.

from cookie-session.

alvarotrigo avatar alvarotrigo commented on April 25, 2024 2

Did you provide any options at your middleware construction time?

I did as far as I know:

app.use(cookieSession({
  maxAge: 3 * 1000, //20*60*1000, //20 mins
  httpOnly: true,
  secure: true,
  secureProxy: true,
  keys: ['key1', 'key2']
}));

app.use(function(req,res,next ){
    console.log(req.session.user);  //user data
    console.log(req.sessionOptions); //empty array

    req.sessionOptions.maxAge: 4000;
    console.log(req.sessionOptions); //  (maxAge: 4000)

   return next();
});

I managed to solve the problem with the renew of the session thanks to this answer in stackoverflow.

Although I'm not quite sure yet why updating a fake session has anything to do with the renew of session.user maxAge.

from cookie-session.

alvarotrigo avatar alvarotrigo commented on April 25, 2024

Isn't this like a pretty basic feature of any session component?
I saw it was marked as a "question" but... isn't there any simple answer for it?

I would like the sessions to be renewed on every page load (or ajax call). That's how they usually work anywhere.

I've tried doing this, but without success:

app.use(function(req,res,next ){
     req.sessionOptions.maxAge = 3000;
     return next();
});

from cookie-session.

dougwilson avatar dougwilson commented on April 25, 2024

Hi, I'm sorry, but I'm only maintaining this module and did not write it. I don't know enough about it to answer and have not had the time to investigate. I was hoping someone else could answer. I marked it as a question because I assumed it was possible to do what you ask.

If you're saying instead that it's not possible, I can change the label to a feature request instead.

from cookie-session.

alvarotrigo avatar alvarotrigo commented on April 25, 2024

If you're saying instead that it's not possible, I can change the label to a feature request instead.

Nop, just asking as I believe documentation doesn't provide the necessary information.

from cookie-session.

dougwilson avatar dougwilson commented on April 25, 2024

Nop, just asking as I believe documentation doesn't provide the necessary information.

Gotcha, that's what I thought and why I labeled this as a question :) The answer from me is "I don't know", which is why I just labeled it and didn't provide an answer. I'll try to take a look into it sometime in the next few weeks if no one else stops by with an answer :)

from cookie-session.

alvarotrigo avatar alvarotrigo commented on April 25, 2024

req.sessionOptions seems to be always empty unless I set an option.

app.use(function(req,res,next ){
    console.log(req.session.user);  //user data
    console.log(req.sessionOptions); //empty array

    req.sessionOptions.maxAge: 4000;
    console.log(req.sessionOptions); //  (maxAge: 4000)
});

Documentation says:

These options are a shallow clone of what was provided at middleware construction and can be altered to change cookie setting behavior on a per-request basis.

from cookie-session.

dougwilson avatar dougwilson commented on April 25, 2024

Hi! Yes, the documentation says:

These options are a shallow clone of what was provided at middleware construction

Did you provide any options at your middleware construction time? It just contains whatever you gave to the module's constructor. Can you show a full app that reproduces?

from cookie-session.

dougwilson avatar dougwilson commented on April 25, 2024

Hmm. Perhaps the issue is with your console.log(req.sessionOptions) statement? What happens if you replace both console.log(req.sessionOptions)s with console.log(req.sessionOptions.maxAge) in your program above? And what if you replace both with console.log(JSON.stringify(req.sessionOptions))?

from cookie-session.

alvarotrigo avatar alvarotrigo commented on April 25, 2024

Interestingly console.log(req.sessionOptions.maxAge) shows the original value.
Not console.log(req.sessionOptions) or console.log(JSON.stringify(req.sessionOptions))

from cookie-session.

dougwilson avatar dougwilson commented on April 25, 2024

Gotcha, that's what I was expecting from how Node.js works. It sounds like everything is working just fine, then to me. Do you have some kind of use-case in your application to do a console.log(req.sessionOptions)?

from cookie-session.

alvarotrigo avatar alvarotrigo commented on April 25, 2024

Gotcha, that's what I was expecting from how Node.js works.

Why is it?

from cookie-session.

dougwilson avatar dougwilson commented on April 25, 2024

Why is it?

$ node -e 'obj={a:1};console.log(Object.create(obj));console.log(obj.a)'
{}
1

from cookie-session.

dougwilson avatar dougwilson commented on April 25, 2024

The exact same command in Firefox is the following:

> obj={a:1};console.log(Object.create(obj));console.log(obj.a)
Object { a=1 }
1

from cookie-session.

codeaholics avatar codeaholics commented on April 25, 2024

The referenced PR (#49) worked for me - once I added the missing call to next() :-)

from cookie-session.

Bluejay47 avatar Bluejay47 commented on April 25, 2024

I brought up the possibility of adding some method to wrap and standardize the process mentioned in #49 if there is a consensus that doing so make sense.

from cookie-session.

dougwilson avatar dougwilson commented on April 25, 2024

I think this question was answered, and there is a PR even that would add an example to the README.

from cookie-session.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.