diff --git a/extra.go b/extra.go new file mode 100644 index 0000000..c41e5e7 --- /dev/null +++ b/extra.go @@ -0,0 +1,13 @@ +package relayer + +import "context" + +const AUTH_CONTEXT_KEY = iota + +func GetAuthStatus(ctx context.Context) (pubkey string, ok bool) { + authedPubkey := ctx.Value(AUTH_CONTEXT_KEY) + if authedPubkey == nil { + return "", false + } + return authedPubkey.(string), true +} diff --git a/handlers.go b/handlers.go index 7a34cd0..2e77178 100644 --- a/handlers.go +++ b/handlers.go @@ -332,6 +332,7 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) { } if pubkey, ok := nip42.ValidateAuthEvent(&evt, ws.challenge, auther.ServiceURL()); ok { ws.authed = pubkey + ctx = context.WithValue(ctx, AUTH_CONTEXT_KEY, pubkey) ws.WriteJSON(nostr.OKEnvelope{EventID: evt.ID, OK: true}) } else { reason := "error: failed to authenticate"