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.get('currentUser'); is not accessible from User.observe hook #23

Closed
bajtos opened this issue Jan 9, 2017 · 5 comments
Closed

Comments

@bajtos
Copy link
Member

bajtos commented Jan 9, 2017

@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: strongloop/loopback#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
@dehypnosis
Copy link

dehypnosis commented Feb 8, 2017

@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..

@bajtos
Copy link
Member Author

bajtos commented Feb 17, 2017

@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.

@b-admike
Copy link
Member

@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.

@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
Projects
None yet
Development

No branches or pull requests

5 participants