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

I can set but I can't get #108

Closed
omidh28 opened this issue Nov 27, 2016 · 3 comments
Closed

I can set but I can't get #108

omidh28 opened this issue Nov 27, 2016 · 3 comments
Assignees
Labels
support Questions, discussions, and general support

Comments

@omidh28
Copy link

omidh28 commented Nov 27, 2016

I using yar as my session plugin along with catbox-redis.
This is my configurations:

const Hapi = require('hapi');
const yar  = require('yar');
const hapiServer = new Hapi.Server({
  cache: {
    engine: require('catbox-redis'),
    host: redisAddress,
    port: redisPort
  }
});

hapiServer.connection({
    host: hapiHostAddress,
    port: hapiPort
});

hapiServer.route({
  method: 'GET',
  path: '/test/{key}/{value}',
  handler: function (request, reply) {

      // In MongoDB, this data will be stored in the
      // "!yar" collection within the "hapi-cache" database.
      var data = {};
      data[request.params.key] = request.params.value;
      request.yar.set('example', data);
      return reply(request.yar.get('example'));
  }
});

const yarOptions = {
    storeBlank: false,
    maxCookieSize: 0,
    cache: {
      expiresIn: 24 * 60 * 60 * 1000
    },
    cookieOptions: {
        password: 'the-password-must-be-at-least-32-characters-long',
        isSecure: true
    }
};

hapiServer.register({
  register: yar,
  options: yarOptions
}, function (err) {

  // start your hapiServer after plugin registration
  hapiServer.start(function (err) {
    console.log('info', 'Server running at: ' + hapiServer.info.uri)
  })
})

The problem is that request.yar.get('example') returns the correct data but it doesn't use redis (I'm monitoring redis with redis-cli monitor) even though request.yar.set('example', data) saves the data to redis.

Shouldn't it fetch from redis catch instead?

@devinivy
Copy link
Member

At a glance your configuration looks good. The cookie data should be retrieved from redis during onPreAuth if the yar cookie session id is sent with the request. The cookie data is only written to redis during onPreResponse. Between onPreAuth and onPreResponse the cookie data is maintained in memory, which is why you don't see yar.get() reaching out to redis.

@omidh28
Copy link
Author

omidh28 commented Nov 27, 2016

@devinivy Yeah the problem was that cookies were disabled in requestJs, Thanks!

@omidh28 omidh28 closed this as completed Nov 27, 2016
@devinivy devinivy self-assigned this Nov 27, 2016
@Marsup Marsup added support Questions, discussions, and general support and removed question labels Sep 21, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

3 participants