rename auth-related fields on WebSocket struct.

This commit is contained in:
fiatjaf 2023-11-29 12:23:21 -03:00
parent 888ac8c1c0
commit 84d01dc1d3
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 8 additions and 8 deletions

View File

@ -46,7 +46,7 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
ws := &WebSocket{
conn: conn,
Challenge: hex.EncodeToString(challenge),
WaitingForAuth: make(chan struct{}),
Authed: make(chan struct{}),
}
ctx = context.WithValue(ctx, WS_KEY, ws)
@ -177,8 +177,8 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
case *nostr.AuthEnvelope:
if rl.ServiceURL != "" {
if pubkey, ok := nip42.ValidateAuthEvent(&env.Event, ws.Challenge, rl.ServiceURL); ok {
ws.Authed = pubkey
close(ws.WaitingForAuth)
ws.AuthedPublicKey = pubkey
close(ws.Authed)
ctx = context.WithValue(ctx, AUTH_CONTEXT_KEY, pubkey)
ws.WriteJSON(nostr.OKEnvelope{EventID: env.Event.ID, OK: true})
} else {

View File

@ -12,8 +12,8 @@ type WebSocket struct {
// nip42
Challenge string
Authed string
WaitingForAuth chan struct{}
AuthedPublicKey string
Authed chan struct{}
}
func (ws *WebSocket) WriteJSON(any any) error {