nip17: fix nil pointer

Fixes a nil pointer when the Publish succeeds.
In that case the err is nil, and calling .Error() on nil causes a nil
pointer exception.
Reproduced at: https://play.golang.com/p/ps8d82Qt9kO
This commit is contained in:
Alessio Perugini 2025-01-05 15:21:41 +01:00 committed by fiatjaf_
parent defc349e57
commit 967a08fb65

View File

@ -55,7 +55,7 @@ func PublishMessage(
}
err = r.Publish(ctx, event)
if strings.HasPrefix(err.Error(), "auth-required:") {
if err != nil && strings.HasPrefix(err.Error(), "auth-required:") {
authErr := r.Auth(ctx, func(ae *nostr.Event) error { return kr.SignEvent(ctx, ae) })
if authErr == nil {
err = r.Publish(ctx, event)