Koa2 cannot get cookie using ctx.cookies.get

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
        }
    }
})

> 
Mar.23,2021

ctx.cookies.set adds the Set-Cookie field to the HTTP response header.
ctx.cookies.get reads the Cookie field from the HTTP request header.
from the server's point of view, it first receives the request request from the client, and then outputs the response response. So the cookie of ctx.cookies.set can only get


through ctx.cookies.get the next time request. Sometimes, the value of AAA is set from this.cookies.get ('AAA'), but the value taken out is empty.
add the following two properties, and that's fine. The settings of httpOnly and secure should be the same.
this.cookies.get ('AAA', {httpOnly: false, signed: false});
this.cookies.set (' AAA', cityShort, {
httpOnly: false,
signed: false,
});
httpOnly: sets whether the key-value pair can be accessed by js. By default, true, is not allowed to be accessed by js.
secure: signed: sets whether to sign the Cookie. If it is set to true, the value of the key-value pair will be signed at the same time, and checked later to prevent the frontend from tampering with this value. The default is true.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b2e7-2b7bd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b2e7-2b7bd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?