The vaccines do not prevent infection. They make our body better able to handle the infection and prevent developing severe symptoms for up to 95% of people after the second shot. Thus less hospitalization and fewer deaths. The trials did not study whether they lesson the ability of an infected person to spread the disease.
This is something that, to my understanding is not yet clear, and they are gathering data to determine whether you can be an asymptomatic carrier after being vaccinated.
Also from what i've read, specific to Pfizer, but i would think it would not be much different for the Moderna, same platform, same technology, after the first shot, it takes a few weeks to develop immunity, and the first shot will get you about
52% immunity. Its a week after the second shot, that most will gain 95% immunity