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

context.params.user is empty object #635

Closed
dengunya opened this Issue Feb 7, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@dengunya
Copy link

dengunya commented Feb 7, 2018

Using auth.hooks.authenticate(['jwt'])
Trying to get current user from hook.
There is context.params.user but it's empty object.
Changing "entity" option works, still context.params['entity'] is empty.
Am i doing something wrong ?

Steps to reproduce

Use auth.hooks.authenticate(['jwt']) hook
Use own hook afterwards and try getting context.params.user

Expected behavior

context.params.user populated with user object (or at least userId)

Actual behavior

context.params.user is empty object

Module versions (especially the part that's not working):
"@feathersjs/authentication": "^2.1.1",
"@feathersjs/authentication-jwt": "^1.0.2",
"@feathersjs/authentication-local": "^1.0.4",

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Feb 9, 2018

What does the encoded JWT you are sending look like? I'm suspecting it does not have a userId?

@dengunya

This comment has been minimized.

Copy link
Author

dengunya commented Feb 12, 2018

@daffl

What does the encoded JWT you are sending look like?

Here's genetated token:
eyJhbGciOiJIUzI1NiIsInR5cCI6ImFjY2VzcyJ9.eyJpYXQiOjE1MTg0MjU3NTgsImV4cCI6MTUxODUxMjE1OCwiYXVkIjoiaHR0cHM6Ly9kb21haW4uY29tIiwiaXNzIjoiZmVhdGhlcnMiLCJzdWIiOiJhbm9ueW1vdXMiLCJqdGkiOiIzNGYyNzYwOS0yM2FhLTQ0OWMtYWQ1NC1iMmM3OTU1MmMxM2UifQ.mN1lEoUck7vY0o1vnoimn6TaS6ujX7qhyjd1bVzMW-U

Seems there's no userId. Do you have any thoughts why it can be so ?

@dengunya

This comment has been minimized.

Copy link
Author

dengunya commented Feb 13, 2018

The problem is that I don't call authentication service directly, but do smth. like:

  app.post('/users/authenticate', function (req, res, next) {
    app.service('/authentication').create({
      strategy: 'local',
      email: req.body.email,
      password: req.body.password
    }).then(token => {
        res.send(token);
    });
  });

because I need to avoid passing "strategy", just username and password and use another url.
And I wonder if I can pass User to params from Authentication After Create Hook.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Feb 13, 2018

That information would've been quite useful at the beginning ;) Only external calls are expected to pass authentication information like that (on the server you can just create any token you want) so you'll have to pass params.provider to make it look like an external call:

  app.post('/users/authenticate', function (req, res, next) {
    app.service('/authentication').create({
      strategy: 'local',
      email: req.body.email,
      password: req.body.password
    }, { provider: 'express' }).then(token => {
        res.send(token);
    });
  });

@daffl daffl closed this Feb 15, 2018

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.