-
Notifications
You must be signed in to change notification settings - Fork 21
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
Crash with mongodb connector due to getCurrentContext() #12
Comments
Nevermind, it is the same issue as strongloop/loopback#2519 Apparently they think about deprecating the getCurrentContext() method as it creates a lot of issues: strongloop/loopback#1676 |
Apologies for a late addition to this issue. I tried your patch as mentioned here and it did not seem to help us. We can use the component in memory. That works as expected. If we then attach a Mongo or Postgres data source it fails. We can authenticate but any permitted request is rejected. The logs took us to L316 of utils. LoopBackContext.getCurrentContext({ bind: true }).set('groupAccessApplied', true) Can you point us in the right direction? ... loopback:security:access-context getUserId() companyAdminA +0ms TypeError: Cannot read property 'set' of null |
Hey @BuchyOne In the end - after many days of trying - we ditched loopback-context completely and no longer use it. Instead, we now do things the recommended way in loopback 3 (see https://loopback.io/doc/en/lb3/Using-current-context.html) which is a horrible hacky solution that relies on manually passing the context throughout your app. Unfortunately, this seems to be the only reliable way to do things. The loopback-component-access-groups component does still use loopback-context under the hood, but we have also introduced a custom strong-remoting phase (see https://loopback.io/doc/en/lb3/Using-current-context.html#use-a-custom-strong-remoting-phase) which makes the current user and user groups available via loopback's see loopback-component-access-groups/lib/utils.js Lines 42 to 56 in 75ad901
Much as I hate to promote a horrible workaround, I would suggest that you look to follow the loopback 3.x recommendations for handing current context. |
Overlooked to mention that we encountered this after upgrading from loopback-connector-mongodb@1.15.1 So Greg's comments are still applicable. |
Hi Tom, Thanks for the speedy reply! Reading those docs now, I get the gist ... Cheers from downunder |
Someone found the solution for this problem? Using new versions of loopback-connector-mongodb still loses context (null). The problem happens on the utils.js on (loopback-component-access-groups) (setupRoleResolver() method) |
Your component is great but I run into crashes when I use the mongodb connector.
It happens when trying to call
set()
on anull
object returned fromthis.app.loopback.getCurrentContext()
https://github.com/fullcube/loopback-component-access-groups/blob/master/lib/utils.js#L298
To reproduce it you can change the datasource in your simple-app using this configuration:
There are many issues on loopback's github project about mongodb and
getCurrentContext()
, they are probably related, but they are all "Closed".strongloop/loopback#885
strongloop/loopback#809
and more
Using the memory connector works fine.
I am using the latest packages:
The text was updated successfully, but these errors were encountered: