Move duplicated auth code into one place