refactor authentication helper