Skip to content

Commit 6429189

Browse files
authored
Merge pull request #136 from fiatjaf/check-auth-required
check reason auth-required before sending AUTH envelop
2 parents f2fcda7 + 1afe5a5 commit 6429189

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

handlers.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/json"
99
"fmt"
1010
"net/http"
11+
"strings"
1112
"time"
1213

1314
"github.com/fasthttp/websocket"
@@ -359,6 +360,13 @@ func (s *Server) handleMessage(ctx context.Context, ws *WebSocket, message []byt
359360
notice = "unknown message type " + typ
360361
}
361362
}
363+
364+
// NIP-42 auth challenge
365+
if strings.HasPrefix(notice, "auth-required:") {
366+
if _, ok := s.relay.(Auther); ok {
367+
ws.WriteJSON(nostr.AuthEnvelope{Challenge: &ws.challenge})
368+
}
369+
}
362370
}
363371

364372
func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
@@ -415,11 +423,6 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
415423
return nil
416424
})
417425

418-
// NIP-42 auth challenge
419-
if _, ok := s.relay.(Auther); ok {
420-
ws.WriteJSON(nostr.AuthEnvelope{Challenge: &ws.challenge})
421-
}
422-
423426
for {
424427
typ, message, err := conn.ReadMessage()
425428
if err != nil {

0 commit comments

Comments
 (0)