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

Loopback context is cleared on calling bcrypt to compare password #28

Closed
1 of 2 tasks
ali-nahid opened this issue Apr 10, 2017 · 4 comments
Closed
1 of 2 tasks
Labels

Comments

@ali-nahid
Copy link

ali-nahid commented Apr 10, 2017

Bug

My loopback context is lost if I call bcrypt compare function
bcrypt.compare(currentPassword, user.password, function(err, isMatch) {



});

  • Bug
  • Feature request

Description of feature (or steps to reproduce if bug)

When I tried to call the bcrypt within any model of my loopback application

//Loopback context available here
var LoopBackContext = require('loopback-context');
var context = LoopBackContext.getCurrentContext();
console.log(context); //Loopback context available here
bcrypt.compare(currentPassword, user.password, function(err, isMatch) {

    //Loopback context available here
    var LoopBackContext = require('loopback-context');
    var context = LoopBackContext.getCurrentContext();
    console.log(context); //Loopback context available here gives null ?
    if (isMatch) {
        //Perform my operation.
    }
});

//Loopback context available here
var LoopBackContext = require('loopback-context');
var context = LoopBackContext.getCurrentContext();
console.log(context); //Loopback context available here gives null ?

Or If I use the inbuilt method to compare password the same thing goes

//Loopback context available here
var LoopBackContext = require('loopback-context');
var context = LoopBackContext.getCurrentContext();
console.log(context); //Loopback context available here
userObject.hasPassword((currentPassword, function(err, isMatch) {

    //Loopback context available here
    var LoopBackContext = require('loopback-context');
    var context = LoopBackContext.getCurrentContext();
    console.log(context); //Loopback context available here gives null ?
    if (isMatch) {
        //Perform my operation.
    }
});

//Loopback context available here
var LoopBackContext = require('loopback-context');
var context = LoopBackContext.getCurrentContext();
console.log(context); //Loopback context available here gives null ?

After a bit research I found the the the internal method of loopback hasPassword for user Model uses the bcrypt library and the same goes there too !

Additional information (Node.js version, LoopBack version, etc)

  "loopback": "^3.2.1",
  "loopback-boot": "^2.23.0",
  "loopback-component-explorer": "^4.0.0",
  "loopback-connector-mongodb": "1.15.1",
  "loopback-context": "^3.0.0",
@ali-nahid ali-nahid changed the title Loopback context is cleared on calling bcrypt to check old password Loopback context is cleared on calling bcrypt to compare password Apr 10, 2017
@josieusa
Copy link
Collaborator

josieusa commented Apr 10, 2017

Hi,
I'm currently experimenting with a solution for another issue, which I hope could work for this one too, if it works and when it's ready.
See also
#21 (comment)

@josieusa
Copy link
Collaborator

josieusa commented Apr 10, 2017

Provided that bcrypt is the cause of the issue (I didn't try to reproduce it yet), another solution could be to shim the NPM module which is causing the issue (bcrypt in this case), in order to make it work fine with cls-hooked.

(It is a fork of continuation-local-storage used by loopback-context).

This is a common approach. The problem is that cls-bcrypt (the shimmed version of bcrypt) looks unmantained.

If you wish, you could fork cls-bcrypt, update its dependencies at least, and if it still works, and tests still pass, then publish it on NPM under a slightly different name (don't forget to cite the original project in your README).

And then you could submit a PR to loopback, where you replace the dependency bcrypt with your published cls-bcrypt-whatever.

Also, this is less general than the solution I'm working on, but I would find it perfectly fine anyway.

But I'm not a community maintainer of loopback, so I suggest you to ask to a Loopback maintainer before you start to work on all this stuff.

@stale
Copy link

stale bot commented Feb 11, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 11, 2020
@stale
Copy link

stale bot commented Feb 27, 2020

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants