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

Payload won't include userId when logging in with stored localStorage token #496

Closed
kingmatusevich opened this Issue May 4, 2017 · 8 comments

Comments

Projects
None yet
5 participants
@kingmatusevich
Copy link

kingmatusevich commented May 4, 2017

I have feathers set with local authentication and jwt only (the standard config with feather generator).
When logging in with the local strategy and the credentials, the payload will have userId as expected. When logging in calling just authenticate() on the connection upgrade to sockets, having a token set in localstorage, It works, but it doesn't contain userId, causing all sorts of unexpected behaviors.

Steps to reproduce

socket.io.engine.on('upgrade', function (transport) {
      console.log('transport changed');
      client.authenticate().then(something => {
        console.log('UPGRADE CONNECTION', something);
        return client.passport.verifyJWT(something.accessToken);
      })
      .then(payload => {
        console.log('JWT Payload', payload);
        return client.service('users').get(payload.userId);
      })
      .then(user => {
        client.set('user', user);
        console.log('User', client.get('user'));
      })
      .catch(function (error) {
        console.log("Error Authenticating!", error);
      });
    });

Expected behavior

Tell us what should happen
It should bring the user.

Actual behavior

Tell us what happens instead

info: error: users - Method: get: Current user is missing 'id' field.
error:  Error: Current user is missing 'id' field.
    at /Users/javiermatusevich/Development/Sistel/ecommerce/node_modules/feathers-authentication-hooks/lib/query-with-current-user.js:
28:13
    at Object.<anonymous> (/Users/javiermatusevich/Development/Sistel/ecommerce/node_modules/feathers-authentication-hooks/lib/restric
t-to-owner.js:26:9)
    at process._tickCallback (internal/process/next_tick.js:109:7)

System configuration

Tell us about the applicable parts of your setup.

Module versions

{
  "name": "ecommerce",
  "description": "",
  "version": "0.0.0",
  "homepage": "",
  "main": "src",
  "keywords": [
    "feathers"
  ],
  "author": {
    "name": "Javier Matusevich",
    "email": "javiermatusevich@gmail.com"
  },
  "contributors": [],
  "bugs": {},
  "directories": {
    "lib": "src"
  },
  "engines": {
    "node": ">= 6.0.0",
    "yarn": ">= 0.18.0"
  },
  "scripts": {
    "test": "npm run eslint && npm run mocha",
    "eslint": "eslint src/. test/. --config .eslintrc.json",
    "mocha": "mocha test/ --recursive",
    "jest": "jest",
    "start": "node $NODE_DEBUG_OPTION src/",
    "webpack-win": "echo f | xcopy /Y client\\index.html public\\index.html && webpack --colors --progress --watch",
    "webpack-unix": "echo f | mkdir -p ./public | cp -f client/index.html ./public/index.html && webpack --progress --colors --watch",
    "webpack-unix-production": "echo f | mkdir -p ./public && cp -f client/index.html ./public/index.html && (webpack --progress --colors || true)"
  },
  "jest": {
    "testPathDirs": [
      "__jest__"
    ]
  },
  "dependencies": {
    "axios": "0.15.3",
    "body-parser": "^1.17.1",
    "compression": "^1.6.2",
    "cors": "^2.8.3",
    "dauria": "^1.1.5",
    "eslint": "^3.19.0",
    "feathers": "^2.1.1",
    "feathers-authentication": "^1.2.2",
    "feathers-authentication-hooks": "^0.1.2",
    "feathers-authentication-jwt": "^0.3.1",
    "feathers-authentication-local": "^0.3.4",
    "feathers-blob": "^1.2.0",
    "feathers-client": "^2.1.0",
    "feathers-configuration": "^0.4.1",
    "feathers-errors": "^2.6.3",
    "feathers-hooks": "^2.0.0",
    "feathers-hooks-common": "^3.0.0",
    "feathers-rest": "^1.7.2",
    "feathers-socketio": "^1.6.0",
    "fs-blob-store": "^5.2.1",
    "helmet": "^3.5.0",
    "http-proxy-middleware": "^0.17.4",
    "immutable": "3.8.1",
    "lodash": "4.17.4",
    "mocha": "^3.3.0",
    "multer": "^1.3.0",
    "nuka-carousel": "2.0.4",
    "passport": "^0.3.2",
    "pluralize": "3.1.0",
    "query-string": "4.3.1",
    "react": "^15.4.2",
    "react-debounce-input": "^2.4.2",
    "react-dimensions": "1.3.0",
    "react-dom": "15.4.2",
    "react-dropzone": "3.10.0",
    "react-images": "0.5.2",
    "react-redux": "5.0.2",
    "react-router": "3.0.2",
    "react-router-redux": "4.0.7",
    "react-throttle": "0.3.0",
    "redux": "3.6.0",
    "redux-actions": "1.2.1",
    "redux-logger": "2.8.0",
    "redux-saga": "0.14.3",
    "request": "^2.81.0",
    "request-promise": "^4.2.0",
    "semantic-ui-css": "2.2.4",
    "semantic-ui-react": "0.64.7",
    "serve-favicon": "^2.4.2",
    "socket.io-client": "1.7.2",
    "superagent": "3.4.4",
    "winston": "^2.3.1"
  },
  "devDependencies": {
    "babel-core": "^6.23.1",
    "babel-jest": "18.0.0",
    "babel-loader": "^6.4.0",
    "babel-polyfill": "^6.23.0",
    "babel-preset-es2015": "6.22.0",
    "babel-preset-react": "6.22.0",
    "babel-preset-stage-0": "^6.22.0",
    "babel-preset-stage-2": "6.22.0",
    "css-loader": "0.26.1",
    "electron": "1.4.15",
    "file-loader": "0.10.0",
    "jest": "18.1.0",
    "jshint": "2.9.4",
    "mocha": "^3.3.0",
    "source-map-loader": "0.1.6",
    "style-loader": "0.13.1",
    "ts-loader": "2.0.0",
    "typescript": "2.1.5",
    "url-loader": "0.5.7",
    "webpack": "2.1.0-beta.22"
  }
}
@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented May 4, 2017

What do the hooks on the authentication service look like?

@kingmatusevich

This comment has been minimized.

Copy link
Author

kingmatusevich commented May 4, 2017

@marshallswain

module.exports = function () {
  const app = this;
  const config = app.get('authentication');

  // Set up authentication with the secret
  app.configure(authentication(config));
  app.configure(local(config.local));
  app.configure(jwt());
  

  // The `authentication` service is used to create a JWT.
  // The before `create` hook registers strategies that can be used
  // to create a new valid JWT (e.g. local or oauth2)
  app.service('authentication').hooks({
    before: {
      create: [
        authentication.hooks.authenticate(config.strategies),
        
      ],
      remove: [
        authentication.hooks.authenticate('jwt'),
        specialLogger('log out')
      ]
    }
  });
};

@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented May 5, 2017

Oh. Did you get it resolved @kingmatusevich?

@kingmatusevich

This comment has been minimized.

Copy link
Author

kingmatusevich commented May 5, 2017

yes, the users service didn't have defined the id property that represent the fieldName for the id.

@kingmatusevich

This comment has been minimized.

Copy link
Author

kingmatusevich commented May 5, 2017

I had a custom implementation of the service

@bertho-zero

This comment has been minimized.

Copy link
Contributor

bertho-zero commented May 6, 2017

I have the same issue, when I refresh my page the payload of token loss the userId.

@rcostalenz

This comment has been minimized.

Copy link

rcostalenz commented May 12, 2017

Same problem here.

@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented May 12, 2017

For those having this issue, can you please verify that the strategy is getting sent in the request? Also, make sure you have the authenticate hook as a before hook on the /authentication strategy. It sounds like the jwt authentication request isn't hitting the jwt strategy and you're hitting the implicit anonymous auth (which will hopefully be removed in the near future).

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.