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 #2004

Closed
barocsi opened this issue Jan 29, 2016 · 6 comments
Closed

context.get('currentUser'); is not accessible from User.observe hook #2004

barocsi opened this issue Jan 29, 2016 · 6 comments
Assignees
Labels

Comments

@barocsi
Copy link

barocsi commented 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
Copy link
Contributor

jannyHou commented Feb 1, 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
Copy link
Author

barocsi commented Feb 1, 2016

This is a custom user model. I will check against the sandbox repo.

@KaanErkol
Copy link

any solutions ?

@bajtos
Copy link
Member

bajtos commented Jun 7, 2016

Possibly related: #2397

@jannyHou
Copy link
Contributor

jannyHou commented Jun 7, 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
Copy link
Member

bajtos commented Jan 9, 2017

Issue moved to strongloop/loopback-context #23 via ZenHub

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

4 participants