Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7646411

Browse files
author
ludovic
committed
Merge remote-tracking branch 'origin/master'
2 parents 632c02b + 9d623ef commit 7646411

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

‎README.md

Lines changed: 2 additions & 0 deletions
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

Lines changed: 8 additions & 1 deletion
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 {
@@ -178,9 +179,15 @@ export class Websocket {
178179
if (channel.name.startsWith('private-') || channel.name.startsWith('presence-')) {
179180
this.options.debug && console.log(`Sending auth request for channel ${channel.name}`)
180181

182+
if (this.options.bearerToken) {
183+
this.options.auth.headers['Authorization'] = 'Bearer ' + this.options.bearerToken;
184+
}
185+
181186
axios.post(this.options.authEndpoint, {
182187
socket_id: this.getSocketId(),
183188
channel_name: channel.name,
189+
}, {
190+
headers: this.options.auth.headers || {}
184191
}).then((response: AxiosResponse) => {
185192
this.options.debug && console.log(`Subscribing to channels ${channel.name}`)
186193

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /