refactor auth logic;