There is conflicting research in this area. It's too early to declare any definitive conclusions yet.
https://www.medrxiv.org/content/10.1101/2021.08.24.21262415v...
https://www.medrxiv.org/content/10.1101/2021.08.24.21262415v...
Nonetheless, this study should not be taken as an endorsement that getting infected is a better overall option for protection than the highly effective vaccines.