Put the authenticate functionality in its own function, and added it to every view