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

UseMiddleware doesn't work as expected with subscriptions #592

Closed
rigelglen opened this issue Apr 1, 2020 · 1 comment
Closed

UseMiddleware doesn't work as expected with subscriptions #592

rigelglen opened this issue Apr 1, 2020 · 1 comment
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists

Comments

@rigelglen
Copy link

Describe the bug
I have a custom checker middleware that I'm using on regular queries with @UseMiddleware(CustomMiddleware), when I try to use that on a subscription, the middleware is not called when the subscription is first queried (which is when authorization checks should happen). The middleware is called when the resolver receives a pubsub message.

However, if I use @Authorized(), the auth checker middleware gets called when you first query the subscription.

To Reproduce

@UseMiddleware(CustomMiddlware)
@Subscription(
topics: 'SOME_TOPIC'
)
async mySubscription()

// Middleware will only get called when a new message comes in.

Expected behavior
Middleware should get called when first subscribing to the subscription (onConnect)

Environment (please complete the following information):

  • OS: any
  • Node 13.12.0
  • Package version: 0.18.0-beta.10 (also tested on 0.17.6)
  • TypeScript version 3.8.3

Additional context

I've set up a minimal test repo here https://github.com/rigelglen/typegraphql-middleware-subscription-test

You can reproduce using the following

subscription{
  normalSubscriptionWithMiddleware{
    id
    message
    date
  }
}

And then

mutation {
  pubSubMutation(message: "something")
}
@rigelglen rigelglen changed the title UseMiddleware doesn't work with subscriptions UseMiddleware doesn't work as expected with subscriptions Apr 1, 2020
@rigelglen rigelglen changed the title UseMiddleware doesn't work as expected with subscriptions UseMiddleware doesn't work as expected with subscriptions. Apr 1, 2020
@rigelglen rigelglen changed the title UseMiddleware doesn't work as expected with subscriptions. UseMiddleware doesn't work as expected with subscriptions Apr 1, 2020
@MichalLytek
Copy link
Owner

Duplicate of #200 🔒

For now only @Authorized is supported during subscribe phase.
However, as a workaround you can provide custom subscribe function that will contain the auth logic.

@MichalLytek MichalLytek added Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists labels Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants