Skip to content

Commit 2f0eb9f

Browse files
authored
Handle unauthorized user events gracefully (#15071)
1 parent 78e8f62 commit 2f0eb9f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

routers/events/events.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ func Events(ctx *context.Context) {
3030
ctx.Resp.Header().Set("X-Accel-Buffering", "no")
3131
ctx.Resp.WriteHeader(http.StatusOK)
3232

33+
if !ctx.IsSigned {
34+
// Return unauthorized status event
35+
event := (&eventsource.Event{
36+
Name: "unauthorized",
37+
Data: "sorry",
38+
})
39+
_, _ = event.WriteTo(ctx)
40+
ctx.Resp.Flush()
41+
return
42+
}
43+
3344
// Listen to connection close and un-register messageChan
3445
notify := ctx.Req.Context().Done()
3546
ctx.Resp.Flush()

routers/routes/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func RegisterRoutes(m *web.Route) {
400400
})
401401
}, reqSignOut)
402402

403-
m.Any("/user/events", reqSignIn, events.Events)
403+
m.Any("/user/events", events.Events)
404404

405405
m.Group("/login/oauth", func() {
406406
m.Get("/authorize", bindIgnErr(auth.AuthorizationForm{}), user.AuthorizeOAuth)

0 commit comments

Comments
 (0)