From 7d16aa1168d91c02048adeef501c9574372cdfe2 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 20 Jun 2026 20:25:09 -0300 Subject: [PATCH] khatru: OnAuth hook. --- khatru/handlers.go | 3 +++ khatru/relay.go | 1 + 2 files changed, 4 insertions(+) diff --git a/khatru/handlers.go b/khatru/handlers.go index a27fa26..4cfc68a 100644 --- a/khatru/handlers.go +++ b/khatru/handlers.go @@ -346,6 +346,9 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) { } ws.authLock.Unlock() ws.WriteJSON(nostr.OKEnvelope{EventID: env.Event.ID, OK: true}) + if rl.OnAuth != nil { + rl.OnAuth(ctx, pubkey) + } } else { ws.WriteJSON(nostr.OKEnvelope{EventID: env.Event.ID, OK: false, Reason: "error: failed to authenticate: " + err.Error()}) } diff --git a/khatru/relay.go b/khatru/relay.go index 69898eb..bc9e3d7 100644 --- a/khatru/relay.go +++ b/khatru/relay.go @@ -85,6 +85,7 @@ type Relay struct { RejectConnection func(r *http.Request) bool OnConnect func(ctx context.Context) OnDisconnect func(ctx context.Context) + OnAuth func(ctx context.Context, pubkey nostr.PubKey) OnListenerAdded func(ws *WebSocket, ssid int, id string, filter nostr.Filter) OnListenerRemoved func(ws *WebSocket, ssid int, id string, filter nostr.Filter) OverwriteRelayInformation func(ctx context.Context, r *http.Request, info nip11.RelayInformationDocument) nip11.RelayInformationDocument