lahsivjar / react-stomp

React websocket component for STOMP protocol over SockJs
https://www.npmjs.com/package/react-stomp
MIT License
134 stars 41 forks source link

Not able to pass custom header in sockjsClient #162

Open jitugeo opened 4 years ago

jitugeo commented 4 years ago

I,m not able to pass the token in the header using SockjsClient. Here is my code

const customHeader = { Authorization: 'Basic token' }; this.stompClient.connect(customHeader, (res) => { }, (error) => { }) @lahsivjar can you help me what I'm missing here ? Thanks

aminmc commented 4 years ago

I do this and it works:

<SockJsClient
      url={`http://localhost:8080/ws`}
      topics={topics}
      headers={
          {
            Authorization: `Bearer token`,
          }
      }
      debug
      onMessage={(msg) => {
        ...do something
      }}
    />
ur-gh commented 1 year ago
@aminmc   It did not work for me.. can you see what is different here when you have a moment

<SockJsClient url={SOCKET_URL} topics={topics} headers={ { Authorization: Bearer ${accessToken}, } } subscribeHeaders={ { Authorization: Bearer ${accessToken}, } } onConnect={onConnected} onDisconnect={console.log("Disconnected!")} onMessage={msg => onMessageReceived(msg)} debug={false} />

ur-gh commented 1 year ago

@jitugeo Just wondering if you were able to find a solution to pass header? I am tryign to padd Authorization header with oauth token. Thanks!

RapidFire05 commented 1 year ago

i also cannot get headers to stick. the back end keeps thinking the Authorization header is null even though it can correctly handle other secured endpoints. I feel like its just a formatting issue on the prop but cant seem to get it to work.