summaryrefslogtreecommitdiffstats
path: root/internal/handler/websocket/handler.go
diff options
context:
space:
mode:
authorbndw <ben@bdw.to>2026-02-15 09:03:45 -0800
committerbndw <ben@bdw.to>2026-02-15 09:03:45 -0800
commit9b97943680a9675809f942a75c0a8ea4747ce5bb (patch)
tree379e9971202a47d7152bce5bb16addc6371ea763 /internal/handler/websocket/handler.go
parent71f7a444398275923246e1bc8283938a63a8267a (diff)
fix: send OK response when AUTH required but not completed
Previously when an EVENT was received before authentication was completed, the relay would send an AUTH challenge but silently drop the EVENT without sending an OK response. This caused clients to timeout waiting for the OK that never came. Now the relay immediately sends OK false with "auth-required" message, so clients know the EVENT was rejected and can retry after AUTH completes. Also optimized to parse the event JSON only once instead of twice.
Diffstat (limited to 'internal/handler/websocket/handler.go')
-rw-r--r--internal/handler/websocket/handler.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go
index 35d0aea..5201698 100644
--- a/internal/handler/websocket/handler.go
+++ b/internal/handler/websocket/handler.go
@@ -262,8 +262,16 @@ func (h *Handler) handleEvent(ctx context.Context, conn *websocket.Conn, raw []j
262 return err 262 return err
263 } 263 }
264 264
265 // Parse event to get ID for OK response
266 var event nostr.Event
267 if err := json.Unmarshal(raw[1], &event); err != nil {
268 status = "error"
269 return fmt.Errorf("invalid event: %w", err)
270 }
271
265 if state.authenticatedPubkey == "" && h.authConfig != nil && h.authConfig.WriteEnabled { 272 if state.authenticatedPubkey == "" && h.authConfig != nil && h.authConfig.WriteEnabled {
266 status = "unauthenticated" 273 status = "unauthenticated"
274 h.sendOK(ctx, conn, event.ID, false, "auth-required: authentication required")
267 return nil 275 return nil
268 } 276 }
269 277
@@ -279,11 +287,7 @@ func (h *Handler) handleEvent(ctx context.Context, conn *websocket.Conn, raw []j
279 } 287 }
280 } 288 }
281 289
282 var event nostr.Event 290 // Event already parsed above for auth check
283 if err := json.Unmarshal(raw[1], &event); err != nil {
284 status = "error"
285 return fmt.Errorf("invalid event: %w", err)
286 }
287 291
288 if !event.CheckID() { 292 if !event.CheckID() {
289 status = "error" 293 status = "error"