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

isProvider() not working as expected #678

Closed
uplke opened this issue Jun 14, 2022 · 2 comments
Closed

isProvider() not working as expected #678

uplke opened this issue Jun 14, 2022 · 2 comments

Comments

@uplke
Copy link

uplke commented Jun 14, 2022

Consider a provider check in a hook:
iff(isProvider('external'), doSomethingForExternal())

Expected behavior

doSomethingForExternal() is executed only if context.params.provider === 'external'

Actual behavior

doSomethingForExternal() is executed if context.params.provider === 'rest'

Replacing isProvider() works as expected:
iff(context => context.params.provider === 'external', doSomethingForExternal())

Module versions v6.1.0
Possibly an issue with the comparison in index.js - line 784:
providers.some((provider) => provider === hookProvider || provider === "server" && !hookProvider || provider === "external" && !!hookProvider)

@uplke uplke changed the title isProvider() not working correctly isProvider() not working as expected Jun 14, 2022
@fratzinger
Copy link
Collaborator

It's not a bug, it's a feature ™️

How does it come, that you use context.params.provider as 'external'? I don't know any feathers library, that does this.
isProvider expects your input as: 'socketio' | 'rest' | 'primus' | undefined. That are the common values for context.params.provider. If you set it yourself, please set it to socketio or rest to be consistent with other libraries.

@uplke
Copy link
Author

uplke commented Jun 14, 2022

Thx for the quick reply and the good work - I was missing the valid values for context.params.provider that isProvider extends-)
For complete reference:
https://docs.feathersjs.com/api/services.html#params
context.params.provider can be 'socketio' | 'rest' | 'primus' | undefined

https://hooks-common.feathersjs.com/utilities.html#isprovider
isProvider extends this and accepts 'socketio' | 'rest' | 'primus' | 'external' | 'server'

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

2 participants