Closed mkrakiewicz closed 3 years ago
It looks like you have issues with the polyfil version indeed. I'd suggest that you open an issue there to help handling errors.
I have used this with Cookies for authorization as they work well and are secure, indeed you have to specify cookie policies for it to work (see https://mercure.rocks/spec#authorization). Note also that with HttpOnly cookies this authorization is pretty transparent for the javascript developer.
it seems it's not possible to send the JWT simply as a query parameter?
no you can't
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi, I'm trying to subscribe with auth to Mercure. The native EventSource works OK without authentication.
TLDR: the js lib https://github.com/Yaffle/EventSource used in the examples for custom Header auth throws me errors constantly in the development version.
AFAIK to authenticate I need to either: a) use cookies (but this requires to have Mercure and WWW to have on the same domain, which is very restricting) b) use JS polyfills to send a custom header with
Authorization: Bearer
c) it seems it's not possible to send the JWT simply as a query parameter?I've tried to use cookies but it fails for different domains (I need this for testing at the moment). So I've turned to polyfills but they would throw weird errors, so I looked into the demo to get the exact lib&version (since it works and doesn't throw any errors * ):
The
@1
is in fact 1.0.20 now: https://cdn.jsdelivr.net/npm/event-source-polyfill@1.0.20In the demo, or when I use the CDN version, I see no errors in the console.
But I work with webpack as it should be, and I assume most people do. When I use non-minified version of this lib I get errors every ~15 seconds:
The code still works, but the errors are unexpected.
So, does the demo use correct js for error handling? How to handle those errors / reconnects properly? Because this doesn't happen in the native EventSource.
* - It seems it only doesn't throw errors all the time, because it uses a minified version, which has stripped
console.error
calls.EDIT:
I've degraded version to 1.0.19 and the console log is removed and I can use a listener to get errors manually.