Skip to content

Commit 48ef04e

Browse files
authored
Drop the event source if we are unauthorized (#15275)
A previous commit that sent unauthorized if the user is unauthorized simply leads to the repeated reopening of the eventsource. # This PR changes the event returned to tell the client to close the eventsource and thus prevents the repeated reopening. Signed-off-by: Andrew Thornton <[email protected]>
1 parent f2715b8 commit 48ef04e

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

routers/events/events.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func Events(ctx *context.Context) {
3333
if !ctx.IsSigned {
3434
// Return unauthorized status event
3535
event := (&eventsource.Event{
36-
Name: "unauthorized",
37-
Data: "sorry",
36+
Name: "close",
37+
Data: "unauthorized",
3838
})
3939
_, _ = event.WriteTo(ctx)
4040
ctx.Resp.Flush()

web_src/js/features/eventsource.sharedworker.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Source {
1010
this.listening = {};
1111
this.clients = [];
1212
this.listen('open');
13+
this.listen('close');
1314
this.listen('logout');
1415
this.listen('notification-count');
1516
this.listen('stopwatches');

web_src/js/features/notification.js

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export async function initNotificationCount() {
7474
});
7575
worker.port.close();
7676
window.location.href = AppSubUrl;
77+
} else if (event.data.type === 'close') {
78+
worker.port.postMessage({
79+
type: 'close',
80+
});
81+
worker.port.close();
7782
}
7883
});
7984
worker.port.addEventListener('error', (e) => {

web_src/js/features/stopwatch.js

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export async function initStopwatch() {
5555
});
5656
worker.port.close();
5757
window.location.href = AppSubUrl;
58+
} else if (event.data.type === 'close') {
59+
worker.port.postMessage({
60+
type: 'close',
61+
});
62+
worker.port.close();
5863
}
5964
});
6065
worker.port.addEventListener('error', (e) => {

0 commit comments

Comments
 (0)