Skip to content

Commit

Permalink
chore: add information about preloaded file
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz committed Oct 20, 2023
1 parent bf91b1c commit 4615efb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,18 @@ transmit.broadcast('users/1/posts', { username: 'lanz' })
You can mark a channel as private and then authorize the client to subscribe to it. The authorization is done using a callback function.

```ts
// start/transmit.ts

import type { HttpContext } from '@adonisjs/core/http'

transmit.authorizeChannel<{ id: string }>('users/:id', (ctx: HttpContext, { id }) => {
return ctx.auth.user?.id === +id
})
```

> **NOTE**
> Do not forget to add your `start/transmit.ts` file inside the `preloads` array of the `adonisrc.ts` file.
When a client tries to subscribe to a private channel, the callback function is invoked with the channel params and the HTTP context. The callback function must return a boolean value to allow or disallow the subscription.

# Syncing
Expand Down

0 comments on commit 4615efb

Please sign in to comment.