Sails.js + Passport.js authentication through websockets

前端 未结 4 1476
醉梦人生
醉梦人生 2020-12-08 04:22

When I use Sails.js with Passport.js, the isAuthenticated method does not exist on the req object when requested through websocket.

Could anyone tell me why this hap

4条回答
  •  囚心锁ツ
    2020-12-08 05:16

    Please try to check for req.session.passport.user. It will contain user info when logged in, and will be undefined otherwise. Works for me with any type of request.

    I think this happens because in case of WebSocket request, "req" is actually fake request object. It created and passed directly to Express' router, bypassing all Express' middleware, including Passport's one

提交回复
热议问题