raveljs / ravel

Forge past a tangle of node.js modules. Make a cool app.
http://raveljs.github.io/docs/latest/
MIT License
21 stars 6 forks source link

Access and populate session on initialization #263

Closed adamocarolli closed 5 years ago

adamocarolli commented 5 years ago

Session cookies are not set when session has not been accessed and populated. This is documented in koa-session's test suite: https://github.com/koajs/session/blob/master/test/cookie.test.js

describe('when accessed and not populated', () => {
      it('should not Set-Cookie', done => {
        const app = App();

        app.use(async function(ctx) {
          ctx.session;
          ctx.body = 'greetings';
        });

        request(app.listen())
        .get('/')
        .expect(200, (err, res) => {
          if (err) return done(err);
          res.header.should.not.have.property('set-cookie');
          done();
        });
      });
    });
Ghnuberath commented 5 years ago

Is this a problem? If this is the default behaviour of koa-session, then I'd assume they'd intend for something creating the session to populate it. Which would put that responsibility in the territory of an AuthenticationProvider, or any client writing custom code that involves sessions.

I wouldn't want to integrate it into Ravel's core, as that extra piece of behaviour would have unnecessary performance implications for those just using Ravel to create plain, sessionless REST APIs.

adamocarolli commented 5 years ago

Agreed. Closed.