mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-11-24 04:58:59 +01:00
remove unused .OnAuth() and update README example.
This commit is contained in:
21
README.md
21
README.md
@@ -76,16 +76,17 @@ func main() {
|
|||||||
return false, "" // anyone else can
|
return false, "" // anyone else can
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
relay.OnConnect = append(relay.OnConnect,
|
|
||||||
func(ctx context.Context) {
|
// you can request auth by rejecting an event or a request with the prefix "auth-required: "
|
||||||
// request NIP-42 AUTH from everybody
|
relay.RejectFilter = append(relay.RejectFilter,
|
||||||
khatru.RequestAuth(ctx)
|
func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) {
|
||||||
},
|
if pubkey := khatru.GetAuthed(ctx); pubkey != "" {
|
||||||
)
|
log.Printf("request from %s\n", pubkey)
|
||||||
relay.OnAuth = append(relay.OnAuth,
|
return false, ""
|
||||||
func(ctx context.Context, pubkey string) {
|
}
|
||||||
// and when they auth we just log that for nothing
|
return true, "auth-required: only authenticated users can read from this relay"
|
||||||
log.Println(pubkey + " is authed!")
|
// (this will cause an AUTH message to be sent and then a CLOSED message such that clients can
|
||||||
|
// authenticate and then request again)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
// check the docs for more goodies!
|
// check the docs for more goodies!
|
||||||
|
|||||||
@@ -69,12 +69,8 @@ func main() {
|
|||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
return true, "auth-required: only authenticated users can read from this relay"
|
return true, "auth-required: only authenticated users can read from this relay"
|
||||||
},
|
// (this will cause an AUTH message to be sent and then a CLOSED message such that clients can
|
||||||
)
|
// authenticate and then request again)
|
||||||
relay.OnAuth = append(relay.OnAuth,
|
|
||||||
func(ctx context.Context, pubkey string) {
|
|
||||||
// and when they auth we can just log that for nothing
|
|
||||||
log.Println(pubkey + " is authed!")
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
// check the docs for more goodies!
|
// check the docs for more goodies!
|
||||||
|
|||||||
1
relay.go
1
relay.go
@@ -54,7 +54,6 @@ type Relay struct {
|
|||||||
DeleteEvent []func(ctx context.Context, event *nostr.Event) error
|
DeleteEvent []func(ctx context.Context, event *nostr.Event) error
|
||||||
QueryEvents []func(ctx context.Context, filter nostr.Filter) (chan *nostr.Event, error)
|
QueryEvents []func(ctx context.Context, filter nostr.Filter) (chan *nostr.Event, error)
|
||||||
CountEvents []func(ctx context.Context, filter nostr.Filter) (int64, error)
|
CountEvents []func(ctx context.Context, filter nostr.Filter) (int64, error)
|
||||||
OnAuth []func(ctx context.Context, pubkey string)
|
|
||||||
OnConnect []func(ctx context.Context)
|
OnConnect []func(ctx context.Context)
|
||||||
OnDisconnect []func(ctx context.Context)
|
OnDisconnect []func(ctx context.Context)
|
||||||
OnEventSaved []func(ctx context.Context, event *nostr.Event)
|
OnEventSaved []func(ctx context.Context, event *nostr.Event)
|
||||||
|
|||||||
Reference in New Issue
Block a user