Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth doesn't work with non default local.userEndpoint #159

Closed
juodumas opened this Issue Apr 14, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@juodumas
Copy link
Contributor

juodumas commented Apr 14, 2016

Auth doesn't work when using a custom userEndpoint (app.configure(authentication({local: {userEndpoint: '/api/users'}}))). Confirmed in 2 cases:

  • with a custom idField on feather-memory service
  • with feathers-nedb (simply app.use('users', nedbService({Model: db})))
  • didn't test other DBs

A gist with feathers-memory: https://gist.github.com/juodumas/67793c57ebbbde0e5e606b43675dea5e

When using feathers-rest, server log shows:

TypeError: Cannot read property 'get' of undefined
    at <...>/feathers-authentication/lib/hooks/populate-user.js:30:45 

When using sockets, app.authenticate() is rejected and returns the hook object.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Apr 14, 2016

@juodumas you need to specify your idField in your authentication config and bring the userEndpoint top level.

app.configure(authentication({
  idField: 'id',
  userEndpoint: '/api/users'
}

You can find all the config options here: http://docs.feathersjs.com/authentication/readme.html. Also make sure you are using v0.7 as some of those options had changed from v0.5.

@ekryski ekryski closed this Apr 14, 2016

@juodumas

This comment has been minimized.

Copy link
Contributor Author

juodumas commented Apr 14, 2016

No, that's not it. Just try setting up feathers-nedb auth with any custom userEndpoint.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Apr 15, 2016

@juodumas ok well if you are using nedb then your idField needs to be _id. You said you were using feathers-memory.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Apr 15, 2016

I think in order to help out I'd need to see more code. If you want to fire a link to the app or add a gist that would be great.

@juodumas

This comment has been minimized.

Copy link
Contributor Author

juodumas commented Apr 15, 2016

The key was putting userEndpoint at the top level of auth options, just as you said initially. Missed it, sorry.

Would it be possible for feathers to be more verbose about such errors to help later newcomers like me? Right now when I incorrectly set local: {userEndpoint: '/api/users'}, app.authenticate() got rejected and returned the following object over sockets, but otherwise feathers was silent. Only later when testing did I add feathers-rest and saw an exception in the server log. Why is an exception thrown when using rest and not thrown when using sockets?

{
  "hook": {
    "data": {
      "id": "admin",
      "email": "admin",
      "password": "$2a$10$eWUbRA52A2H/899dnNPPru2EpMf8cFqNiw8KK5I24SrJaz6.9MBfK",
      "_id": "2e42YoJFgqRHo6AB"
    },
    "params": {
      "data": {
        "id": "admin",
        "email": "admin",
        "password": "$2a$10$eWUbRA52A2H/899dnNPPru2EpMf8cFqNiw8KK5I24SrJaz6.9MBfK",
        "_id": "2e42YoJFgqRHo6AB"
      }
    },
    "method": "create",
    "type": "after",
    "result": {
      "_id": "2e42YoJFgqRHo6AB",
      "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJfaWQiOiIyZTQyWW9KRmdxUkhvNkFCIiwiaWF0IjoxNDYwNzA1MTk2LCJleHAiOjE0NjA3OTE1OTYsImlzcyI6ImZlYXRoZXJzIn0.u6-2eu4FHfwAyP4_4_QAOudhMJf3hsBGWUj1b03EIvc"
    }
  }
}

Thanks for the replies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.