At 40, I've done some of the best work I've ever done and my pay has been better than ever. I'm 52 now and the trend has only gotten better.
Why? Its because at 40, I had a much deeper understanding of the tech, I understood of the whole business process and I had the maturity to deal with people in a productive way. You won't find all of those in a 25 year old developer.
The only way that age becomes a detriment is if you do not grow. I worked with someone my age who only strong skills are a large enterprise storage system. He is a dinosaur and his future is limited. That's not his age, its the way he chose to build is CV.
I focused on learning new tech; Python, Go, Kubernetes, Cloud, etc. I've also spend a lot of time learning the business aspects of my industry and I've learned to be less of a jerk to people and how to communicate. At 52, I have recruiters contact me all the time.
Age is just number guys. Stay current, keep learning and stay strong.