在用eggjs寫用戶登錄, 用戶登錄成功后,在session里放入userasync login() { const ctx = this.ctx; const { username, password } = ctx.request.body; const user = await this.service.home.login(username, password); ctx.session.user = user; const { id, schemastr } = user || {}; console.log(ctx.session); ctx.body = { data: { id, schemastr, username, }, message: 'success', }; } 問題是,在設(shè)置session完之后,其它c(diǎn)ontroller函數(shù)的session都為空對(duì)象:async asyncData() { const ctx = this.ctx; const { id, schemastr } = ctx.request.body; this.service.home.asyncData(id, schemastr); console.log(ctx.session); // => {} ctx.body = { data: 200, message: 'success', }; } 請(qǐng)問大家是怎么回事?
eggjs 如何使用session控制用戶登錄
溫溫醬
2019-03-12 17:15:23