How did they use to sleep in the shul?
In Eruvin 74b.2, the Gemara rejects a proof by saying:
לְעוֹלָם אֵימָא לָךְ קַיבְּלַהּ מִינֵּהּ, וְהָכָא חַזָּנָא הוּא דַּהֲוָה אָכֵיל נַהֲמָא בְּבֵיתֵיהּ וְאָתֵי בָּיֵית בְּבֵי כְנִישְׁתָּא
The Gemara rejects this proof. Actually, you can say that Shmuel accepted Rabbi Elazar’s objection and retracted his opinion, and here there was a synagogue attendant who would eat bread in his own house that was located elsewhere, but would come and sleep in the synagogue, which was open to the alleyway.
My question is on the bold parts. There is a halacha in Orach Chaim 151:3,
אין ישנים בב"ה אפילו שינת עראי
It is forbidden to have even a short nap in a synagogue
So how can it be that the attendant would sleep in the shul?