Get user id socket.io, passport, koa

后端 未结 2 994
無奈伤痛
無奈伤痛 2021-02-10 08:20

I\'m using Koa, Passport.js and koa-session to authenticate users. So it basically looks like:

// session
var session = require(\'koa-session\');
app.keys = [con         


        
2条回答
  •  情深已故
    2021-02-10 08:28

    I used a regex to grab the userId and found then in my database. Not the cleanest approach but it works well. I'm just using koa-session-store as my session with passport js.

      var cookies = socket.request.headers.cookie;
      var regEx = /passport"\:\{"user"\:"(.+?)"\}/g
      var userIdMatches = regEx.exec(cookies);
    

提交回复
热议问题