It sounds like you're  trying to access that's on an organizational site on ArcGIS.com (youcompany.maps.arcgis.com) When I have to access items on my organization, I have to use OAuthInfo and IdentityManager to log in.
This is an example of the code I use to get items that aren't public
    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/FeatureLayer",
      "esri/identity/OAuthInfo",
      "esri/identity/IdentityManager"
    ], function (Map, MapView, FeatureLayer, OAuthInfo, identityManager) {
      let layer, map, view;
      const portalUrl = 'https://yourCompany.maps.arcgis.com';
      const info = new OAuthInfo({
        appId: "xxxxxxxxxxxxxxx", //*** Your Client ID value goes here ***//
        popup: false // inline redirects don't require any additional app configuration
      });
      identityManager.registerOAuthInfos([info]);
      // send users to arcgis.com to login
      identityManager.getCredential(portalUrl);
      identityManager.checkSignInStatus(portalUrl).then(function () {
        layer = new FeatureLayer({
          portalItem: {
            id: "itemID"
          },
          outFields: ["*"]
        });
        map = new Map({
          basemap: 'oceans',
          layers: [layer]
        });
        view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-153, 63],
          zoom: 4,
          popup: {
            autoOpenEnabled: false
          }
        });
      });
    });