I want to take koa-session to remember user login state. And after reading docs and code ,I got blocked by the concept store session in cookie.
I take this code to show my understanding
route --> /signin
router.post('signin', async ctx => {
/*
* parse http request body param-->(userName, password)
*/
ctx.session.userList = ctx.session.userList || [] // userList to register user who have logged
if (ctx.session.userList.indexOf(userName) === -1) {
ctx.throw (400, 'user is online')
} else {
// check userName and password in db
ctx.session.userList.push(userName)
ctx.status=200 // response to browser and create a cookie (key as config.key, value as encode(session))
}
})
In this way, anyOne who visits route signin will recieve a cookie. And as more users log in, userList in session and cookie(key.value) both will grow.
Is this a correct understaning?I used to store session id in db to implement this situation so i'm really not certain about this. Please show me something if it's wrong, thanks a lot.
I want to take
koa-session
to remember user login state. And after reading docs and code ,I got blocked by the conceptstore session in cookie
.I take this code to show my understanding route -->
/signin
In this way, anyOne who visits route
signin
will recieve a cookie. And as more users log in,userList
in session andcookie(key.value)
both will grow.Is this a correct understaning?I used to store session id in db to implement this situation so i'm really not certain about this. Please show me something if it's wrong, thanks a lot.