refactor auth code.