you cannot get cookie by using ctx.cookies.get in koa2. The print result is always undefined.
the code is as follows
//
router.post("/user/login", async (ctx, next) => {
let {username, pwd} = ctx.request.body;
let result = await User.findOne({username});
console.log(result)
if(!result){
return ctx.body = {
code:0,
msg: ""
}
} else if(result.pwd === md5Pwd(pwd)) {
console.log(result._id); //
ctx.cookies.set("userid", result._id);
console.log(ctx.cookies.get("userid")); // undefined
return ctx.body = {
code:1,
msg: "",
data: result
}
}
})
>