Different authors are motivated by different things - that's so obvious that it almost goes without saying. I think it's important to understand how you are motivated to write, though, because the framing is actually really important for deep introspection - for figuring out both how you tick as an artist and how you can maximize your motivation while increasing your confidence as an author (or reducing your self-doubt).
There's a concept in psychology of loci of control - do you control your destiny or is it controlled by forces beyond your influence? Motivation works the same way. You can be internally motivated by things like your desire to tell a good story, to write well, to gain experience as a writer, or just to get your idea out into the world. These are things that are internal - nobody but you controls them, and they are independent of whatever anybody else thinks about your work. You can also be externally motivated by things like reader feedback, making money as a writer, or getting the most readers. Personally, I think it is important to have both internal and external motivations, because internal motivations give you an intrinsic drive than nobody and nothing can take away. However, external motivations give you real-world metrics and goals to guide yourself. Both are important. However, when you find yourself encountering doubt because of how your audience or the world in general views (or doesn't view) your writing, then it's time to turn to your internal motivations and give your externalizing a rest.
To some extent, whether you internalize or externalize is inherent to your psychology, so you can't just flip it on a switch. But understanding how your motivations are a mixture of both can help you to focus on one or the other, depending on how your work needs to evolve and improve as you develop as a writer. And, if you find yourself beset by self-doubt, it may be useful to ignore externalities and think about your own self-driven motivations.