The simple answer to this question is that we do not know. Not yet, anyhow.
The immunity you gain from a viral infection is known as ‘natural immunity.’ The length of time we are protected in this way varies between diseases, and we will not know this figure for Covid-19 until we have more data, analyzed over a longer period of time. We do know that recatching coronavirus within 90 days of initial infection is uncommon.
More data must also be conducted on vaccines, and how long they can provide immunity. Vaccines have not been in circulation for very long, and thus we need more time before we can fully understand how long ‘vaccine immunity’ lasts.