Interplay between superconductivity and antiferromagnetism in a multilayered system