refactor and debug User is not authorized