extracted authentication logic to service