The truth is you have to do good work for yourself because you care about the quality of your work. You work for you.
You separate the factors. You do good work for you because you care because a life doing things you don't care about is less meaningful.
Separately you look at pay. You leave when it's no longer worth staying, which for most people is about every two to three years at least for your early career.