Good job noticing this issue. It is not valid to divide by a quantity that could be zero. Fortunately, there are two easy ways to deal with the situation.
Split the proof into two cases: one where the quantity is zero, and one where it is not zero. The first case is usually pretty easy, and division is valid in the second case
Instead of dividing, try factoring instead. e.g. to solve the equation $x \sin x = \sin x,$ rather than dividing by $\sin x$, instead do $x \sin x - \sin x = 0,$ $(x-1) \sin x = 0$ and now you can invoke the usual theorem that says this is equivalent to "$\sin x = 0$ or $x-1 = 0$" and continue from there. Of course, this isn't too much different from option #1.
In some cases, there are other things you can do. For example, you might be able to prove an identity under the assumption that a certain quantity is nonzero, and then use some other means to prove it in the remaining case.
As a contrived example, suppose I had to assume $x \neq 0$ to prove $ 2 \sin x \cos x = \sin 2x.$ I could finish the proof by observing both sides are continuous: $ 2 \sin 0 \cos 0 = \lim_{x \to 0} 2 \sin x \cos x = \lim_{x \to 0} \sin 2x = \sin (2 \cdot 0). $ This is a good trick for a variety of situations. (of course, in this particular case, it would be easier to just plug in $x=0$ to verify the identity holds) (penartur's answer has other examples)
Also, I should point out that this isn't just an abstract concern, or a pedantic point to counter silly "proofs" that 2=1. Sometimes, those extra cases really matter.
For example, in multi-variable calculus, a lot of people have trouble with Lagrange multipliers, since the answer you want quite frequently comes from the "assume the quantity is zero" case, rather than from "divide by the quantity because I'm going to assume it's nonzero" case.