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

Error while using /auth/local #233

Closed
rohitketkar87 opened this Issue Jul 7, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@rohitketkar87
Copy link

rohitketkar87 commented Jul 7, 2016

I am getting strange error...
I registered two users using my "/users" service in same session.
I was able to login with first user using his username and password.
However when I tried to login with second user, it threw following error.

NotAuthenticated: Invalid login. at Object.construct (D:\POCs\feathers_tutorials\my_feather-app\node_modules\core-js\modules\es6.reflect.construct.js:23:24) at NotAuthenticated.ExtendableBuiltin (D:\POCs\feathers_tutorials\my_feather-app\node_modules\feathers-errors\lib\index.js:21:28) at NotAuthenticated.FeathersError (D:\POCs\feathers_tutorials\my_feather-app\node_modules\feathers-errors\lib\index.js:99:87) at new NotAuthenticated (D:\POCs\feathers_tutorials\my_feather-app\node_modules\feathers-errors\lib\index.js:152:85) at D:\POCs\feathers_tutorials\my_feather-app\node_modules\feathers-authentication\lib\services\local.js:144:27 at allFailed (D:\POCs\feathers_tutorials\my_feather-app\node_modules\passport\lib\middleware\authenticate.js:94:18) at attempt (D:\POCs\feathers_tutorials\my_feather-app\node_modules\passport\lib\middleware\authenticate.js:167:28) at Strategy.strategy.fail (D:\POCs\feathers_tutorials\my_feather-app\node_modules\passport\lib\middleware\authenticate.js:284:9) at verified (D:\POCs\feathers_tutorials\my_feather-app\node_modules\passport-local\lib\strategy.js:82:30) at D:\POCs\feathers_tutorials\my_feather-app\node_modules\feathers-authentication\lib\services\local.js:120:18 at D:\POCs\feathers_tutorials\my_feather-app\node_modules\bcryptjs\dist\bcrypt.js:261:17 at D:\POCs\feathers_tutorials\my_feather-app\node_modules\bcryptjs\dist\bcrypt.js:1198:21 at Immediate.next [as _onImmediate] (D:\POCs\feathers_tutorials\my_feather-app\node_modules\bcryptjs\dist\bcrypt.js:1078:21) at processImmediate [as _immediateCallback] (timers.js:383:17)
Here is my code:
https://github.com/rohitketkar87/useradministration-feathers.git

@rohitketkar87

This comment has been minimized.

Copy link
Author

rohitketkar87 commented Jul 7, 2016

However i noted that if I register users in two different sessions (stopping server and starting again), I am able to login from both using /auth/local.
I am suspecting that when we use same sessions, "token" returned after registration is same in both the cases which is causing trouble I guess.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Jul 7, 2016

In general Feathers services are stateless so there isn't really any sessions. I did notice some strangeness in https://github.com/rohitketkar87/useradministration-feathers/blob/master/services/userservice.js however. For example userService.after in https://github.com/rohitketkar87/useradministration-feathers/blob/master/services/userservice.js#L173 will register a new hook every time findUserById is getting called so I'm thinking that other things in that file are getting changed up while the application is running.

I'm not sure if services/userservice.js is necessary the way it is right now since your Controller routes could just call the user service directly (via req.app.service('users')):

app.post('/api/registeruser', function(req, res, next) {
  console.log('mainCtrl : registerUser starts');
  var userInput = req.body;

  req.app.service('users').create(userInput).then(function(user) {
    res.json(user);
  }).catch(next);
});
@rohitketkar87

This comment has been minimized.

Copy link
Author

rohitketkar87 commented Jul 7, 2016

@daffl true, right now its not necessary but actually when code grows, it helps to maintain modular structure. Moreover I was just trying out how to fit feathers in my template.
Anyway, to add further to issue, I traced log. I found out that when I try to register second user, userService.before({ create: [authentication.hooks.hashPassword(), function(hook) { console.log('****hook**** '+JSON.stringify(hook, null, 4)); hook.data.createdAt = new Date(); }] }); is getting called twice. Please find attached log.
login error.txt

@rohitketkar87

This comment has been minimized.

Copy link
Author

rohitketkar87 commented Jul 7, 2016

@daffl Resolved the issue. Thanks. Registered all the hooks at one place. Latest code uploaded to repo.

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.