How to trigger portal/agol login from widget if necessary?

876
1
03-21-2017 02:53 PM
by Anonymous User
Not applicable

Hi all.

We are putting together a simple widget that displays a list of webmaps available to a given user. The initial webmap/basemap will be unsecured so there will be nothing within the webmap itself to trigger a login (assuming the user is not logged in already).

How can we get the widget to trigger the generic user login if it's not logged in, followed by continuing on to query for the list of webmaps?

Conceptually, I would have thought that the actual query would trigger a login but that doesn't appear to happen (unless we're doing something wrong).

Happy to take comments, pointers to examples or to provide more info if needed.

Cheers,

-Paul

Tags (2)
0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Paul,

   You should use the jimu/portalUtils:

var portal = portalUtils.getPortal(this.appConfig.portalUrl);
if(!portal.haveSignIn()){
  portal.signIn().then(lang.hitch(this, function(){
    portal.queryItems(params).then(lang.hitch(this, function(searchResponse){ //params: {q,sortField,sortOrder,num,start}
      //do something with the searchResponse
    });
  });
}else{
  portal.queryItems(params).then(lang.hitch(this, function(searchResponse){ //params: {q,sortField,sortOrder,num,start}
    //do something with the searchResponse
  });
}‍‍‍‍‍‍‍‍‍‍‍‍