Fixed error logging and added test coverage for user authentication.