The best treatment I have found for fungus gnats is Azatrol. It is a triterpenoid extracted from Neem seeds. It is OMRI certified. You put it in your water and water the plants with it. It has a latency of 100 hours, after which you may need a second application to fully get rid of them.
Actually, in my experience, with fungus gnats endemic during monsoon season, you will never completely get rid of them until fall but you can keep them mostly suppressed. Some will always find mold in the bathroom or kitchen to lay eggs...
I also put it in the water in my germination dish, with 2.5" coir pots and soil. This is normally a significant breeding ground for fungus gnats and the Azatrol will keep them at bay. Same goes for cloning trays. Dilute Azatrol will not harm seedlings or clones.
Azatrol will control numerous cannabis pests through a broad-spectrum action, acting as a hormone to disrupt feeding and reproduction. Contact with the dilute solution will render fungus gnats immobile (possibly dead) and will certainly inhibit their reproduction. It kills larvae by inhibiting their feeding impulse and by outright preventing them from molting into gnats. It can be used as a foliar spray and is superior to any pesticide you can use, both from a toxicity perspective and because it is organic.
It's great stuff but I will reach through the computer and bitch-slap you if you even think about spraying it on budding cannabis! It is a severe irritant and smoking cannabis contaminated with this stuff could almost literally cause you to cough up a lung and get bronchitis! Insect based pest control for pests on the foliage can be effectively treated with predatory insects and the only thing you should use after budding is underway, if you have a conscience.
Don't get it on your skin, especially in concentrated form. You might wish you had poison ivy instead.