Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

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

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

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

juodumas opened this issue Apr 14, 2016 · 5 comments

Comments

@juodumas
Copy link
Contributor

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
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 as completed Apr 14, 2016
@juodumas
Copy link
Contributor Author

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

@ekryski
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
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
Copy link
Contributor Author

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants