mirror of
https://github.com/fiatjaf/nak.git
synced 2025-08-31 22:10:47 -04:00
support --auth/--sec/--prompt-sec on req
.
This commit is contained in:
17
event.go
17
event.go
@@ -222,27 +222,22 @@ example:
|
||||
ctx, cancel := context.WithTimeout(c.Context, 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
status, err := relay.Publish(ctx, evt)
|
||||
if err == nil {
|
||||
// published fine probably
|
||||
log("%s.\n", status)
|
||||
if err := relay.Publish(ctx, evt); err == nil {
|
||||
// published fine
|
||||
log("success.\n")
|
||||
continue nextline
|
||||
}
|
||||
|
||||
// error publishing
|
||||
if strings.HasPrefix(err.Error(), "msg: auth-required:") && sec != "" && doAuth {
|
||||
// if the relay is requesting auth and we can auth, let's do it
|
||||
log("performing auth... ")
|
||||
st, err := relay.Auth(c.Context, func(evt *nostr.Event) error { return evt.Sign(sec) })
|
||||
if st == nostr.PublishStatusSucceeded {
|
||||
pk, _ := nostr.GetPublicKey(sec)
|
||||
log("performing auth as %s... ", pk)
|
||||
if err := relay.Auth(c.Context, func(evt *nostr.Event) error { return evt.Sign(sec) }); err == nil {
|
||||
// try to publish again, but this time don't try to auth again
|
||||
doAuth = false
|
||||
goto publish
|
||||
} else {
|
||||
// auth error
|
||||
if err == nil {
|
||||
err = fmt.Errorf("no response from relay")
|
||||
}
|
||||
log("auth error: %s. ", err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user