mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-18 05:42:19 +01:00
pass AUTH information to functions via context.
This commit is contained in:
parent
dc594ee32b
commit
0a5624737d
13
extra.go
Normal file
13
extra.go
Normal file
@ -0,0 +1,13 @@
|
||||
package relayer
|
||||
|
||||
import "context"
|
||||
|
||||
const AUTH_CONTEXT_KEY = iota
|
||||
|
||||
func GetAuthStatus(ctx context.Context) (pubkey string, ok bool) {
|
||||
authedPubkey := ctx.Value(AUTH_CONTEXT_KEY)
|
||||
if authedPubkey == nil {
|
||||
return "", false
|
||||
}
|
||||
return authedPubkey.(string), true
|
||||
}
|
@ -332,6 +332,7 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
if pubkey, ok := nip42.ValidateAuthEvent(&evt, ws.challenge, auther.ServiceURL()); ok {
|
||||
ws.authed = pubkey
|
||||
ctx = context.WithValue(ctx, AUTH_CONTEXT_KEY, pubkey)
|
||||
ws.WriteJSON(nostr.OKEnvelope{EventID: evt.ID, OK: true})
|
||||
} else {
|
||||
reason := "error: failed to authenticate"
|
||||
|
Loading…
x
Reference in New Issue
Block a user