trailsjs / sails-auth

Passport-based User Authentication system for sails.js applications. Designed to work well with the sails-permissions module.
https://www.npmjs.org/package/sails-auth
MIT License
266 stars 141 forks source link

req.user always empty when calling /user/me #150

Open Brainshack opened 8 years ago

Brainshack commented 8 years ago

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,

ekzhang commented 8 years ago

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.

smyth64 commented 8 years ago

Got the same problem =/

smyth64 commented 8 years ago

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

movehand commented 7 years ago

+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']
}