Skip to content

Commit

Permalink
Merge pull request #32 from aliasproject/master
Browse files Browse the repository at this point in the history
  • Loading branch information
leob authored Nov 12, 2024
2 parents e7ca7c8 + 99adec3 commit 22ff8bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ window.Echo = new Echo({
broadcaster,
// replace the placeholders
host: 'wss://{api-ip}.execute-api.{region}.amazonaws.com/{stage}',
authEndpoint: '{auth-url}/broadcasting/auth', // Optional: Use if you have a separate authentication endpoint
bearerToken: '{token}', // Optional: Use if you need a Bearer Token for authentication
});
```

Expand Down
6 changes: 6 additions & 0 deletions js-src/Websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,15 @@ export class Websocket {
if (channel.name.startsWith('private-') || channel.name.startsWith('presence-')) {
console.log(`Sending auth request for channel ${channel.name}`)

if (this.options.bearerToken) {
this.options.auth.headers['Authorization'] = 'Bearer ' + this.options.bearerToken;
}

axios.post(this.options.authEndpoint, {
socket_id: this.getSocketId(),
channel_name: channel.name,
}, {
headers: this.options.auth.headers || {}
}).then((response: AxiosResponse) => {
console.log(`Subscribing to channels ${channel.name}`)

Expand Down

0 comments on commit 22ff8bb

Please sign in to comment.