Refactor the user creation middleware