@@ -2,7 +2,8 @@ import { AxiosResponse } from "axios";
2
2
import axios from 'axios' ;
3
3
import { Channel } from "./Channel" ;
4
4
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
+
6
7
export type MessageBody = { event : string , channel ?: string , data : object } ;
7
8
8
9
export class Websocket {
@@ -178,9 +179,15 @@ export class Websocket {
178
179
if ( channel . name . startsWith ( 'private-' ) || channel . name . startsWith ( 'presence-' ) ) {
179
180
this . options . debug && console . log ( `Sending auth request for channel ${ channel . name } ` )
180
181
182
+ if ( this . options . bearerToken ) {
183
+ this . options . auth . headers [ 'Authorization' ] = 'Bearer ' + this . options . bearerToken ;
184
+ }
185
+
181
186
axios . post ( this . options . authEndpoint , {
182
187
socket_id : this . getSocketId ( ) ,
183
188
channel_name : channel . name ,
189
+ } , {
190
+ headers : this . options . auth . headers || { }
184
191
} ) . then ( ( response : AxiosResponse ) => {
185
192
this . options . debug && console . log ( `Subscribing to channels ${ channel . name } ` )
186
193
0 commit comments