# Message bus: channel subscription permission

**URL:** https://meta.discourse.org/t/message-bus-channel-subscription-permission/197995
**Category:** Development
**Created:** [July 23, 2021, 3:48pm UTC](https://meta.discourse.org/t/message-bus-channel-subscription-permission/197995 "2021-07-23T15:48:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![supercobra](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supercobra/32/121142_2.png) [@supercobra](https://meta.discourse.org/u/supercobra)
#### Post date: [July 23, 2021, 3:48pm UTC](https://meta.discourse.org/t/message-bus-channel-subscription-permission/197995/1 "2021-07-23T15:48:22Z")

</div>

Hi there,

I understand message bus publishes to target users as per the documentation:

> [@How discourse stays online (Message Bus, Faye, Long Polling)](https://meta.discourse.org/t/how-discourse-stays-online-message-bus-faye-long-polling/3238/9):
>
> When you publish a message you specify who is allowed to see it:
> 
> ```plaintext
> # only user id 100 will get secret santa
> MessageBus.publish('/secret', 'santa', user_ids: [100])
> 
> ```
> 
> The middleware will not distribute messages to users who are not allowed to see them

However, I am wondering if there is a way to check permission when a client tries to subscribe to a channel, something like this:

```plaintext
MessageBus.on_subscribe('/bank_account_123') do
   if current_user.bank_account == 123
      # subscription granted
   else
     # subscription denied
   end

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 24, 2021, 1:20am UTC](https://meta.discourse.org/t/message-bus-channel-subscription-permission/197995/2 "2021-07-24T01:20:40Z")

</div>

I’m not an expert here, but I think you want to control access on the publishing end where you’re sending stuff to the bus, not on the watching side.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [July 24, 2021, 5:56am UTC](https://meta.discourse.org/t/message-bus-channel-subscription-permission/197995/3 "2021-07-24T05:56:37Z")

</div>

Can you expand a bit more about your use case? What are you trying to build?

---

<div class="post-metadata">

### Author: ![supercobra](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supercobra/32/121142_2.png) [@supercobra](https://meta.discourse.org/u/supercobra)
#### Post date: [July 28, 2021, 6:15pm UTC](https://meta.discourse.org/t/message-bus-channel-subscription-permission/197995/4 "2021-07-28T18:15:26Z")

</div>

We are retooling one of our apps and replacing Action Cable with Message Bus. Our current pattern was to check permission on subscribe but now I think we can use Message Bus the way it is intended. So we are good. Message Bus is very well done btw. 🙂
