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

populate-user.js do not get settings #86

kulakowka opened this Issue Feb 29, 2016 · 2 comments


None yet
2 participants
Copy link

kulakowka commented Feb 29, 2016

This hook do not get settings for local auth from my config/default.json.

I have added configuration to default.json file.

  "host": "localhost",
  "port": 3001,
  "postgres": "postgres://postgres:@localhost:5432/feathers",
  "auth": {
    "token": {
      "secret": "bGGBbrJRXyIPRQW3BLaVp/P9/ounEv2L7qIVGfw3uVePt1eUg4Fi6Ji6Bpjknm9rh9hKHaMLwW7aGBVCejXIxA=="
    "local": {
      "usernameField": "email",
      "userEndpoint": "/api/v1/users",
      "idField": "username"

And i passed settings to feather-authentication:

const authentication = require('feathers-authentication')

module.exports = function () {
  const app = this

  let config = app.get('auth')

  app.set('auth', config)

This comment has been minimized.

Copy link
Contributor Author

kulakowka commented Feb 29, 2016

I also found that options.idField parameter is not actually used. It should be like this:

 * Populate the current user associated with the JWT
const defaults = {
  userEndpoint: '/users',
  passwordField: 'password',
  idField: '_id'

export default function(options = {}){
  options = Object.assign({}, defaults, options);

  return function(hook) {
    // If we already have a current user just pass through
    if (hook.params.user) {
      return Promise.resolve(hook);

    let id;

    // If it's an after hook grab the id from the result
    if (hook.type === 'after') {
      id = hook.result[options.idField];
    // Check to see if we have an id from a decoded JWT
    else if (hook.params.payload) {
      id = hook.params.payload[options.idField];

    // If we didn't find an id then just pass through
    if (id === undefined) {
      return Promise.resolve(hook);

    return new Promise(function(resolve, reject){, {}).then(user => {
        // attach the user to the hook for use in other hooks or services
        hook.params.user = user;

        // If it's an after hook attach the user to the response
        if (hook.result) {
 = Object.assign({}, user = !user.toJSON ? user : user.toJSON());

          // format response
          delete hook.result[options.idField];

        return resolve(hook);

I'll try to do PR with the necessary changes.


This comment has been minimized.

Copy link

ekryski commented Feb 29, 2016

This was closed by #87

@ekryski ekryski closed this Feb 29, 2016

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.