<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Portal.user is null in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/portal-user-is-null/m-p/1031254#M71881</link>
    <description>&lt;P&gt;Has anyone ever try the JS API 4.18 oauth sample at&amp;nbsp;&lt;BR /&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/&lt;/A&gt;&lt;BR /&gt;(save to a local file and run it on localhost or a Dev server) and then find that after signed in (with an AGOL for Organization paid user account) you get a portal.user is null error (from the web console) so that the app breaks on trying to get portal.user.username?&amp;nbsp;&lt;/P&gt;&lt;P&gt;When that happens, if you try to load&amp;nbsp;your own secure layer (additional code) it will get a permission error and will not load, even though the credential exists in the Session Storage.&lt;/P&gt;&lt;P&gt;Why would the Identity Manager grant the login but Portal loads with a portal.user null result?&amp;nbsp; What good is the credential returned by the checkSignedInStatus() if you still cannot access your own services?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 27 Feb 2021 04:04:41 GMT</pubDate>
    <dc:creator>DeanChiang</dc:creator>
    <dc:date>2021-02-27T04:04:41Z</dc:date>
    <item>
      <title>Portal.user is null</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/portal-user-is-null/m-p/1031254#M71881</link>
      <description>&lt;P&gt;Has anyone ever try the JS API 4.18 oauth sample at&amp;nbsp;&lt;BR /&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/&lt;/A&gt;&lt;BR /&gt;(save to a local file and run it on localhost or a Dev server) and then find that after signed in (with an AGOL for Organization paid user account) you get a portal.user is null error (from the web console) so that the app breaks on trying to get portal.user.username?&amp;nbsp;&lt;/P&gt;&lt;P&gt;When that happens, if you try to load&amp;nbsp;your own secure layer (additional code) it will get a permission error and will not load, even though the credential exists in the Session Storage.&lt;/P&gt;&lt;P&gt;Why would the Identity Manager grant the login but Portal loads with a portal.user null result?&amp;nbsp; What good is the credential returned by the checkSignedInStatus() if you still cannot access your own services?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 04:04:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/portal-user-is-null/m-p/1031254#M71881</guid>
      <dc:creator>DeanChiang</dc:creator>
      <dc:date>2021-02-27T04:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Portal.user is null</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/portal-user-is-null/m-p/1031478#M71886</link>
      <description>&lt;P&gt;The code works for me, but what was not clear to me from that sample was when to instantiate the Portal item.&lt;/P&gt;&lt;P&gt;Here is a simple function I wrote that works in my application. You have to initialize the Portal object after the login is successful, using the checkSignInStatus();&lt;/P&gt;&lt;P&gt;After the _portal.load() is successfully executed, then my _portal object is populated with all the Portal properties for the sign-in user, including the user object (_portal.user).&lt;/P&gt;&lt;P&gt;Hope this helps...&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;            var _portal = null,
                _oAuthInfo = null;

            *************************

            registerApplication: function () {
                _oAuthInfo = new OAuthInfo({
                    appId: 'abc123xyz'
                });
                arcgisIdentityManager.registerOAuthInfos([_oAuthInfo]);

                arcgisIdentityManager.checkSignInStatus(_oAuthInfo.portalUrl + "/sharing")
                    .then((r) =&amp;gt; {
                        console.log(r);
                        _portal = new Portal();
                        _portal.load();
                    });
            }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 14:02:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/portal-user-is-null/m-p/1031478#M71886</guid>
      <dc:creator>TommyBramble</dc:creator>
      <dc:date>2021-03-01T14:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Portal.user is null</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/portal-user-is-null/m-p/1032256#M71905</link>
      <description>&lt;P&gt;The basic OAuth sample worked for me too.&amp;nbsp;&amp;nbsp;Basically I want to use the sample method for users to switch between secure mode and public view. For example, without login in, an anonymous user sees a non-editable public view layer that is a view of a protected editable feature layer which can then be added and edited if user with proper permission signs in.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The bug comes up when you build on the sample with more functionality. After signing in, the portal loads. I see a fully populated portal object, with all the right properties , except for portal.user is null. IdentityManager.checkSignedInStatus returns a credential in Session Storage. If you replace portal.user.username with credential.userId you can even do a PortalQuery and list your AGOL items like the sample does. The token is valid because I can string it behind a secure service URL and open the REST endpoint. But my AGOL secure layer that I want to add to a map (after signedInStatus checked and portal loads) fails to load.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did not want to "pre-load" the secure, editable layer by default and prompt every user to login immediately upon opening the web page. I did discover that if you set esriConfig.request.useIdentity=false at the start of require() it will produce this bug.&amp;nbsp; Obviously there are probably other conflicting configs or custom modules in my app that created this issue, and I am now forced to go through my entire source code to debug it.&amp;nbsp; I was just wondering if this is a situation that others might have encountered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 23:54:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/portal-user-is-null/m-p/1032256#M71905</guid>
      <dc:creator>DeanChiang</dc:creator>
      <dc:date>2021-03-02T23:54:02Z</dc:date>
    </item>
  </channel>
</rss>

