When a solar flare hits the earth it can damage certain electrical equipment. If one manages to strike the SpaceX Mars rocket it could possibly damage some significant equipment on board (like navigation and life support). So what can these rockets do to protect themselves from these harmful solar flares and other radiation.
There are three ways we can do with existing tech.
The first is to shield the ship with water. Build the ship like a double-hulled oil-tanker and fill that void between the hulls with water. Water is an excellent absorber of radiation. That water would still be drinkable because gamma-radiation (the type you get from the sun) doesn't contaminate what it hits. The worst a particle would do is cause some hydrogen and oxygen bubbles to form in the water as it smashed the water apart.
The second is to equip the ship with a big magnetic field that would deflect the particles as they approach the ship. All of those particles are ionized so most of them will be deflected by a magnetic field enough to avoid the ship.
Lastly, you want a "storm-cellar"- a big old lead container. For those really bad days where the other two systems aren't enough.
The downside to all of this is weight. Water is heavy and lead is worse; the magnetic option would require something that generates a LOT of power, so that would be heavy too.
Protecting electronics is not a big problem. The feared major impacts on electrical systems on Earth involve interactions between a flare (or coronal mass ejection) and Earth's magnetic field. Once you are away from Earth you get the direct particle impacts, but not the electromagnetic effects. These can cause transient local failures, but spacecraft systems are routinely designed to recover from there.
Protecting humans is a different problem. Most designs feature a protected "storm cellar" within the ship (for instance a space surrounded by relatively absorbent water tanks and food supply lockers, into which the astronauts can retreat for a few hours or days when necessary.