sails-auth icon indicating copy to clipboard operation
sails-auth copied to clipboard

req.user always empty when calling /user/me

Open Brainshack opened this issue 9 years ago • 4 comments

Hello,

I have setup a brand new sails app with sails auth. I am using the local strategy. I create a User as described in the docs and authenticated using /auth/local. The auth call returns the correct user. However, when I call /user/me afterwards, the result is empty. I am using Postman to make the calls. A Cookie with the session id exists, so I suppose there maybe needs to be something else setup? I get the same error, when I try using the socket api from the browser,

Brainshack avatar May 29 '16 06:05 Brainshack

I can confirm I am having the same problem. Did you ever figure out the issue?

It appears to me that the UserController's "me" action isn't being called for some reason, even if you route it directly. I've tried calling "sails.log.info()" in the "me" action, and nothing is being logged. I've also tried editing the response passed in to res.ok(), and that didn't change anything either.

ekzhang avatar Jul 05 '16 20:07 ekzhang

Got the same problem =/

smyth64 avatar Jul 23 '16 04:07 smyth64

I found a solution! Use this: https://github.com/langateam/sails-permissions

Just use the files from sails-permission code! I had problems using sails-auth only, but now everything works like charm :)

(even /user/me) ;)

smyth64 avatar Jul 23 '16 05:07 smyth64

+1 In my case, deserializeUser is never called. So the user object is not attached to req.user. Adding the passport policy for UserController in config/policies.js will invoke deserializeUser, and the user will then be attached, but I'm not sure whether if this is the right way to do it.

In config/policies.js:

UserController: {
  me: ['passport']
}

movehand avatar Oct 20 '16 17:10 movehand