The little flies are gnats, they lay eggs in the top, moist, 1" of mediums like coir or soil.
They don't specifically attack the cannabis but they will eat the roots to get to what they're actually looking for.
Make sure the soil is drying out to an inch depth. If you can't get rid of them that way without making them too thirsty (bad during flower), try topdressing with diatomaceous earth, but be aware that it has very high pH and needs to be used sparingly.
https://www.growweedeasy.com/fungus-gnats
likes 2