Oh god, I know that feeling. Most of the time, I just try not to think about it. I'll focus on the story itself and how I want it to pan out, not on whether that's the best way or at least a good way to go about it. I just go forward little by little, one chapter at a time, then one arc, one volume ... until it's done.
If I do get stuck wondering about the quality and whether I can even write (mostly the latter), I tell myself that what I upload here is sort of just a first draft anyway. If it turns out to be shit or not up to the standard I wanted to achieve originally, I can still go back and change stuff after the first 'draft' is finished. Nobody is keeping me from doing so. In that case, even if it was shit, I can at least make it suck less with a big revision.
So, I try to just focus on finishing that first draft. Everything else can come later. Finishing is always the most important to me.
When I am really, really down and it's just one of
those days, I remember the time I was at my worst, compare it to now, and try to imagine where I want to go. Like, I once nuked my whole writing career at a point where I definitely shouldn't have done so just because some outside circumstances made me extremely unhappy with life in general and writing specifically. But as an end result, I was even more unhappy

So I started over a year later with new ideas. Since then, I finished a whole series and three single-volume novels, as well as some short stories, plus I am writing some other projects at the side that all have several finished volumes already. That is more than I managed to achieve in the time before nuking my original career.
If I compare these two periods in my life, I just realize how much happier I am now. It starts from the small stuff like realizing I am not as compulsive about not making mistakes anymore so writing is more relaxed, I have a better grasp on language, I have a much easier time getting chapters done, I actually get more feedback than before even though it's still not as much as I would sometimes like. There are also some bigger issues, like, I've had my coming out since then and can freely talk about that with my readers and put so much more of
me and the issues I've run into in my stuff. It makes me feel like I am helping myself and also helping others which is a damned good feeling.
So, contrasting helps me with showing me the positive sides and pulling me out of that hole. Then, when I try to imagine how things could be a year from now, or maybe three or five years if I am not as stupid as back then and just continue writing no matter the circumstances, that gives me the drive to pick myself up and actually continue. Like, you finished the volume of this story last year? Well, better work on this new volume this year then. Hey, if you work hard enough, you might even finish two! How awesome would that be?
It might sound strange but that does help me with motivating myself. At the very least, I can open the document again and start to slowly work on at least one chapter. And by that point, I normally get back in the swing and just continue.
Overall, I think that everybody needs to find their own way to deal with these problems though. Like, I am usually an optimistic person and I love small-time statistics so finding positives and looking at numbers of finished things and contrasting them with something or looking at the word count I had last month and trying to one-up myself by just 1k words are things that work wonders for me. It won't necessarily help others though and instead, they might become even more depressed.
So, I think it's important to first realize what type of person you are and what helps you with picking yourself up. Not even just in writing but in general. Some people do well with breaks, some with having specific times to do things, some with lists ... There are many, many, many options that can be given a try. Just give them a chance, see what sticks, and then do more of that.