Should I have had a resistor before my transistor?
Yes, your conclusion is correct. Just insert a 1K resistor in series with the base. But first try with a 10 K resistor and then keep on reducing it by 1K. For a more accurate value of the resistor, use this formula:

$$ R_{base} \approx {h_{FE}} \times \frac {V_{OH} - 0.7V} {I_{FAN}} $$

Where


hFE is the transistor's current gain,
IFAN the fan current as measured when connected to the 12VDC source and
VOH the microcontroller's output high level voltage.