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

context.params.user is empty object #635

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

context.params.user is empty object #635

dengunya opened this issue Feb 7, 2018 · 4 comments

Comments

@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
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
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
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
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 as completed Feb 15, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants