Closed soulxy closed 8 years ago
@soulxy
koa-session2 has already supported koa2, so you do not need to convert
it, just use like this
app.use(session({store:new Store()}))
do not use convert
middleware
I known it,but server response timeout by your demo . So I have to use async/await
, Service can respond, while Cannot set property 'view' of undefined
.... I am a new koa ,use convert
,just try
Sorry,Sorry ...I did a very foolish thing, forgot to start redis, then faced to anther error
TypeError: Cannot assign to read only property 'userObj' of [object Object] at users.js:20:7 at [object Generator].next (native) at step (E:\mywork\koa2.0\routers\users.js:3:191) at E:\mywork\koa2.0\routers\users.js:3:368 at run (E:\mywork\koa2.0\node_modules\runkoa\node_modules\babel-polyfill\node_modules\core-js\modules\es6.promise.js:89:22) at E:\mywork\koa2.0\node_modules\runkoa\node_modules\babel-polyfill\node_modules\core-js\modules\es6.promise.js:102:28 at flush (E:\mywork\koa2.0\node_modules\runkoa\node_modules\babel-polyfill\node_modules\core-js\modules_microtask.js:14:5) at nextTickCallbackWith0Args (node.js:415:9) at process._tickCallback (node.js:344:13)
@soulxy
It seems an error in your router file users.js
, maybe you can check E:\mywork\koa2.0\routers\users.js
and find it. :)
@Secbone
in users.js
, I just write ctx.session.userobj = '...'
...
I tried my best to find question, but just find console.log('typeof session', typeof ctx.session)
, print session is string . And I try to modify your files , Unfortunately, does not find a solution
@soulxy Could you show me the users.js
file ? I think there is something wrong in the userobj
@soulxy Could you also show me the store.js
file? I suspect there may have a problem in set
method.
@soulxy It seems good, I don't know what's wrong with your code, so I wrote a test for the custom store, and it works well. Maybe you can pull the repo and check it. Commit detail
@Secbone
I resolve this issue :) ~~ There are some issues in your get function of Store.js
...
At first time, typeof ctx.session is object,But when you got this type second time, it became string.Since reading redis's value without parsing, "[object object]" appears
@soulxy Good! I just thought somebody's session was not a object, maybe a string, so I didn't check the type of it. How do you think if I check the type?
?? I just parse this value in get function of Store.js , will be fine :)
I followed your demo to add my middleware, found some problem.
my code:
app.js
//if the following ,I cannt view my page;
app.use(session({store:new Store()}))
app.use(convert(session({store: new Store()})));
//the same question// so,I have to write like this... , maybe some problem?
app.use(async (ctx, next) => { session({ store: new Store() }); await next(); });
user.js
let result = {......};
ctx.session.view = result;
error
TypeError: Cannot set property 'view' of undefined at app.js:36:3 at dispatch (E:\mywork\koa2.0\node_modules\koa\node_modules\koa-compose\in dex.js:43:32) at next (E:\mywork\koa2.0\node_modules\koa\node_modules\koa-compose\index. js:44:18) at app.js:31:9 at [object Generator].next (native) at step (app.js:23:1) at app.js:23:1 at new Promise (E:\mywork\koa2.0\node_modules\runkoa\node_modules\babel-po lyfill\node_modules\core-js\modules\es6.promise.js:193:7) at app.js:23:1 at app.js:27:9 at dispatch (E:\mywork\koa2.0\node_modules\koa\node_modules\koa-compose\in dex.js:43:32) at next (E:\mywork\koa2.0\node_modules\koa\node_modules\koa-compose\index. js:44:18) at E:\mywork\koa2.0\node_modules\koa-bodyparser\index.js:60:14 at run (E:\mywork\koa2.0\node_modules\runkoa\node_modules\babel-polyfill\n ode_modules\core-js\modules\es6.promise.js:89:22) at E:\mywork\koa2.0\node_modules\runkoa\node_modules\babel-polyfill\node_m odules\core-js\modules\es6.promise.js:102:28 at flush (E:\mywork\koa2.0\node_modules\runkoa\node_modules\babel-polyfill \node_modules\core-js\modules_microtask.js:14:5) at nextTickCallbackWith0Args (node.js:415:9) at process._tickCallback (node.js:344:13)