mirror of
https://github.com/fiatjaf/khatru.git
synced 2026-04-04 04:34:24 +02:00
filter policy: MustAuth()
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"slices"
|
||||
|
||||
"github.com/fiatjaf/khatru"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
@@ -18,6 +19,14 @@ func NoComplexFilters(ctx context.Context, filter nostr.Filter) (reject bool, ms
|
||||
return false, ""
|
||||
}
|
||||
|
||||
// MustAuth requires all subscribers to be authenticated
|
||||
func MustAuth(ctx context.Context, filter nostr.Filter) (reject bool, msg string) {
|
||||
if khatru.GetAuthed(ctx) == "" {
|
||||
return true, "auth-required: all requests must be authenticated"
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
||||
// NoEmptyFilters disallows filters that don't have at least a tag, a kind, an author or an id.
|
||||
func NoEmptyFilters(ctx context.Context, filter nostr.Filter) (reject bool, msg string) {
|
||||
c := len(filter.Kinds) + len(filter.IDs) + len(filter.Authors)
|
||||
|
||||
Reference in New Issue
Block a user