Skip to content

Commit 9d623ef

Browse files
authored
Merge branch 'master' into master
2 parents b6c5281 + f5e65ed commit 9d623ef

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

README.md

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

js-src/Websocket.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { AxiosResponse } from "axios";
22
import axios from 'axios';
33
import { Channel } from "./Channel";
44

5-
export type Options = { authEndpoint: string, host: string, debug: boolean };
5+
export type Options = { authEndpoint: string, host: string, bearerToken: string, auth: any, debug: boolean };
6+
67
export type MessageBody = { event: string, channel?: string, data: object };
78

89
export class Websocket {
@@ -161,9 +162,15 @@ export class Websocket {
161162
if (channel.name.startsWith('private-') || channel.name.startsWith('presence-')) {
162163
this.options.debug && console.log(`Sending auth request for channel ${channel.name}`)
163164

165+
if (this.options.bearerToken) {
166+
this.options.auth.headers['Authorization'] = 'Bearer ' + this.options.bearerToken;
167+
}
168+
164169
axios.post(this.options.authEndpoint, {
165170
socket_id: this.getSocketId(),
166171
channel_name: channel.name,
172+
}, {
173+
headers: this.options.auth.headers || {}
167174
}).then((response: AxiosResponse) => {
168175
this.options.debug && console.log(`Subscribing to channels ${channel.name}`)
169176

0 commit comments

Comments
 (0)