jpierlot
Maybe it's simply what VikasB said and you are not dong the http.response.setRedirectUrl() or something else is wrong, it's hard to tell without seeing the entire page init code.
Usually there is no automatic redirect from CommunityPage to LoginPage, so that has to come from somewhere, e.g. maybe your CommunityPage has some kind of Role (or something custom?) set that makes it "private" and requires users to login, e.g. some other logic would trigger that redirect to the LoginPage.
Therefore the question: what comes before the code you posted above in the page init script?