refactor auth code into reusable class