Yaffle / EventSource

a polyfill for http://www.w3.org/TR/eventsource/
MIT License
2.11k stars 338 forks source link

How can i detect connection is closed to refresh JWT tokens ? #230

Closed eguvenc closed 2 months ago

eguvenc commented 2 months ago

Every request i send a JWT token at headers. When the connection is closed with 401 reason i want to recreate the EventSource object with new token.

Is there any way to detect connection is open or not ?

Yaffle commented 2 months ago

Listen for error event, you can even change the header by changing the property value

eguvenc commented 2 months ago

I tried to listen error event, it always come null even if connection closed

Yaffle commented 2 months ago

See https://github.com/Yaffle/EventSource/issues/137#issuecomment-599061039

eguvenc commented 2 months ago

thanks, it works fine.

eventSource.onerror = function (event) {
  if (event.status == 401) {

  }        
};