mirror of
https://github.com/aljazceru/khatru.git
synced 2026-01-26 00:14:20 +01:00
new flow for auth based on "auth-required: " rejection messages.
This commit is contained in:
@@ -60,15 +60,20 @@ func main() {
|
||||
return false, "" // anyone else can
|
||||
},
|
||||
)
|
||||
relay.OnConnect = append(relay.OnConnect,
|
||||
func(ctx context.Context) {
|
||||
// request NIP-42 AUTH from everybody
|
||||
relay.RequestAuth(ctx)
|
||||
|
||||
// you can request auth by rejecting an event or a request with the prefix "auth-required: "
|
||||
relay.RejectFilter = append(relay.RejectFilter,
|
||||
func(ctx context.Context, filter nostr.Filter) (reject bool, msg string) {
|
||||
if pubkey := khatru.GetAuthed(ctx); pubkey != "" {
|
||||
log.Printf("request from %s\n", pubkey)
|
||||
return false, ""
|
||||
}
|
||||
return true, "auth-required: only authenticated users can read from this relay"
|
||||
},
|
||||
)
|
||||
relay.OnAuth = append(relay.OnAuth,
|
||||
func(ctx context.Context, pubkey string) {
|
||||
// and when they auth we just log that for nothing
|
||||
// and when they auth we can just log that for nothing
|
||||
log.Println(pubkey + " is authed!")
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user