context.get('currentUser'); is not accessible from User.observe hook
@barocsi commented on Fri Jan 29 2016
I was trying to implement an access filter for my User method depending on the currently logged in user. However, when I try to access, it is undefined:
User.observe('access', function inspectRoles(ctx, next) {
var loopback = require('loopback');
var context = loopback.getCurrentContext();
var user = context.get('currentUser');
}
It works with other presistedModels operation hooks.
@jannyHou commented on Mon Feb 01 2016
Hi @barocsi thanks for your contribution! And any question or suggestion are welcomed! I am trying to reproduce the issue with access hook, are you adding it to your custom user model or the build-in User model in loopback?
Could you fork this sandbox and replace it with your code to prove the problem? Thanks!
@barocsi commented on Mon Feb 01 2016
This is a custom user model. I will check against the sandbox repo.
@KaanErkol commented on Thu Mar 31 2016
any solutions ?
@bajtos commented on Tue Jun 07 2016
Possibly related: https://github.com/strongloop/loopback/issues/2397
@jannyHou commented on Tue Jun 07 2016
i am able to reproduce it with the snippet above:
Web server listening at: http://0.0.0.0:3000
Browse your REST API at http://0.0.0.0:3000/explorer
user: undefined
@bajtos any progress?
I don't know the details of CLS thing. But if you are busy to resolve this, you can give me a hint, so i can contribute..
@dehypnosis I think this may be a general problem of the CLS module we use in [email protected], most likely it's the async library that's breaking the CLS.
Could you please try the latest version of this module and check if the problem is still present? See Usage for instructions how to setup your app.
@dehypnosis @bajtos I was able to get the current user by following the details in Usage as pointed out by Miroslav while trying to reproduce juggler#1250 . If you need any help, please let me know.
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.
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.