GetConnection() and GetAuthed() may return empty.

This commit is contained in:
fiatjaf 2024-07-03 22:16:44 -03:00
parent 2a8b704299
commit 3f73a9690a

View File

@ -22,11 +22,19 @@ func RequestAuth(ctx context.Context) {
} }
func GetConnection(ctx context.Context) *WebSocket { func GetConnection(ctx context.Context) *WebSocket {
return ctx.Value(wsKey).(*WebSocket) wsi := ctx.Value(wsKey)
if wsi != nil {
return wsi.(*WebSocket)
}
return nil
} }
func GetAuthed(ctx context.Context) string { func GetAuthed(ctx context.Context) string {
return GetConnection(ctx).AuthedPublicKey conn := GetConnection(ctx)
if conn != nil {
return conn.AuthedPublicKey
}
return ""
} }
func GetIP(ctx context.Context) string { func GetIP(ctx context.Context) string {