refactor out auth function