Modern smartphones are built with safeguards against overcharging, so charging your phone over night usually doesn't harm it. Lithium-ion batteries, which are used in the majority of smartphones, have built-in systems that cause them to shut off when they are fully charged.
However, how you charge your battery can affect its longevity. Keeping your phone constantly at a very high state of charge—that is, always fully charged—may cause the battery to degrade a little more quickly over time. For maximum longevity, it is generally advised to maintain your phone's battery level between 20% and 80%.
Contemporary smartphones are built to handle overnight charging without causing noticeable problems, and they frequently include features that optimise charging.