Cosmic rays are the main agents in controlling the chemical evolution and setting the ambipolar diffusion time of a molecular cloud. We summarise the processes causing the energy degradation of cosmic rays due to their interaction with molecular hydrogen, focusing on the magnetic effects that influence their propagation. Making use of magnetic field configurations generated by numerical simulations, we show that the increase of the field line density in the collapse region results in a reduction of the cosmic-ray ionisation rate. As a consequence the ionisation fraction decreases, facilitating the decoupling between the gas and the magnetic field.