Skip to content

Commit 22ff8bb

Browse files
authored
Merge pull request #32 from aliasproject/master
2 parents e7ca7c8 + 99adec3 commit 22ff8bb

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ window.Echo = new Echo({
196196
broadcaster,
197197
// replace the placeholders
198198
host: 'wss://{api-ip}.execute-api.{region}.amazonaws.com/{stage}',
199+
authEndpoint: '{auth-url}/broadcasting/auth', // Optional: Use if you have a separate authentication endpoint
200+
bearerToken: '{token}', // Optional: Use if you need a Bearer Token for authentication
199201
});
200202
```
201203

js-src/Websocket.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,15 @@ export class Websocket {
136136
if (channel.name.startsWith('private-') || channel.name.startsWith('presence-')) {
137137
console.log(`Sending auth request for channel ${channel.name}`)
138138

139+
if (this.options.bearerToken) {
140+
this.options.auth.headers['Authorization'] = 'Bearer ' + this.options.bearerToken;
141+
}
142+
139143
axios.post(this.options.authEndpoint, {
140144
socket_id: this.getSocketId(),
141145
channel_name: channel.name,
146+
}, {
147+
headers: this.options.auth.headers || {}
142148
}).then((response: AxiosResponse) => {
143149
console.log(`Subscribing to channels ${channel.name}`)
144150

0 commit comments

Comments
 (0)