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

why the _store is empty each request #119

Closed
DyncKevin opened this issue Apr 11, 2018 · 9 comments
Closed

why the _store is empty each request #119

DyncKevin opened this issue Apr 11, 2018 · 9 comments
Assignees
Labels
support Questions, discussions, and general support

Comments

@DyncKevin
Copy link

hi, sorry to bother you.
just a small question, maybe it's my problem but i can't find out way to solve it.

in each request i call request.yar.set(userId, {token: value}); to store user info, and i can get token value in this request. but, next time request with same api, i can't get userId's token value, i console out request.yar, the _store is empty.
at first i thought it's because of the difference of request.yar.id, so i use the same request.yar.id by customSessionIDGenerator, the yar._store is also empty.

my question is that: in first request i set userId value, how to get userId value in next request.

my manifest is like this:

manifest = {
server: {
port: envKey('port'),
routes: {
cors: true
},
router: {
stripTrailingSlash: true
},
cache: [
{
name: 'redisCache',
engine: require('catbox-redis'),
host: '127.0.0.1',
partition: 'cache',
password: '123456'
}
]
},
register: {
plugins: [
{
plugin: 'yar', // this is for session
options: {
storeBlank: false,
maxCookieSize: 1024,
errorOnCacheNotReady: true,
name: 'session',
cache: {
cache: 'redisCache',
expiresIn: 600*1000,
segment: 'session'
},
cookieOptions: {
password: 'querasdf123456789012345678901234567890qwerasdf',
clearInvalid: true,
ignoreErrors: true,
isSameSite: 'Strict',
isHttpOnly: true,
isSecure: false,
ttl: 120000
},
customSessionIDGenerator: function(){
return "123456";
}
}
}
],
options: {
once: true
}
}
};

@andrewnaeve
Copy link

I am also calling request.yar.set('hi', {key: 'hello'}) and getting undefined calling request.yar.get('hi') on the next request. Hapi v 16.1.0.

@Marsup
Copy link
Contributor

Marsup commented Apr 17, 2018

Can you both check that the cookie is actually set in the browser ?

@DyncKevin
Copy link
Author

DyncKevin commented Apr 17, 2018

@Marsup thank you very much, it is the cookie setting problem.

@DyncKevin DyncKevin reopened this Apr 17, 2018
@DyncKevin
Copy link
Author

another question, if my configure above is using catbox-redis or redis, after yar.set, why can't i get the value by redis-client. when I enter redis cmd like "keys userId" or "get userId", I got nothing.

@Marsup
Copy link
Contributor

Marsup commented Apr 17, 2018

catbox has absolutely nothing to do with yar.

@DyncKevin
Copy link
Author

the meaning of this sentence “If the content is too big to fit, it uses server storage via the hapi plugin cache interface.” is that only when the data size is over cookie size, the server storage will be used.
what I should do is config the server like this:
server: {
port: envKey('port'),
routes: {
cors: true
},
router: {
stripTrailingSlash: true
},
cache: [
{
name: 'redisCache',
engine: require('catbox-redis'),
host: '127.0.0.1',
partition: 'cache',
password: '123456'
}
]
}

Am I right ?

@DyncKevin
Copy link
Author

DyncKevin commented May 8, 2018

hi , it seems that chrome do not allow get and send cookie, i am using vue+axios to handle http. i have google a lot, but not find a solution, do you know how to solve it?

@DyncKevin DyncKevin reopened this May 8, 2018
@hueniverse
Copy link
Contributor

Please open a new issue instead of reopening this one. Also, better to ask the last question in hapijs/discuss.

@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

4 participants