How do I get rid of gnats for good?

I need help! I have over 20 plants in my apartment and I cannot seem to get rid of my gnats! I only water when the soil is completely dry and I wait much longer to water my succulents. The gnats got so bad that I ended up repotting all of my plants in brand new soil and sticking them in a closet with grow lights for 2 weeks. I treated the soil with diluted peroxide and left some gnat traps in with them. After a few days a noticed there weren't any new gnats in the traps and there were none flying around anymore. After the two weeks were up I brought them back out and watered a few of them that were dry. As soon as I did that the gnats just came right back! I don't know what to do that this point and they're getting really annoying. Any advice?