Refactor auth API