refactor authentication api