simplified the client auth logic, credit to http://frederiknakstad.com/2013/01/21/authentication-in-single-page-applications-with-angular-js/