@plasmicapp/react-web 0.2.148 → 0.2.149

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -842,14 +842,17 @@ function _triggerLogin() {
842
842
  function PlasmicPageGuard(props) {
843
843
  var appId = props.appId,
844
844
  authorizeEndpoint = props.authorizeEndpoint,
845
- validRoles = props.validRoles,
845
+ minRole = props.minRole,
846
+ canTriggerLogin = props.canTriggerLogin,
846
847
  children = props.children;
847
848
  var dataSourceCtxValue = usePlasmicDataSourceContext();
848
849
  React__default.useEffect(function () {
849
- if (dataSourceCtxValue && "isUserLoading" in dataSourceCtxValue && !dataSourceCtxValue.isUserLoading && !dataSourceCtxValue.user) {
850
- triggerLogin(appId, authorizeEndpoint);
850
+ if (canTriggerLogin) {
851
+ if (dataSourceCtxValue && "isUserLoading" in dataSourceCtxValue && !dataSourceCtxValue.isUserLoading && !dataSourceCtxValue.user) {
852
+ triggerLogin(appId, authorizeEndpoint);
853
+ }
851
854
  }
852
- }, [dataSourceCtxValue, appId, authorizeEndpoint]);
855
+ }, [dataSourceCtxValue, appId, authorizeEndpoint, canTriggerLogin]);
853
856
  function canUserViewPage() {
854
857
  if (!dataSourceCtxValue) {
855
858
  return false;
@@ -857,12 +860,15 @@ function PlasmicPageGuard(props) {
857
860
  if (!dataSourceCtxValue.user) {
858
861
  return false;
859
862
  }
860
- if (!("roleId" in dataSourceCtxValue.user)) {
863
+ if (!("roleIds" in dataSourceCtxValue.user)) {
864
+ return false;
865
+ }
866
+ if (!Array.isArray(dataSourceCtxValue.user.roleIds)) {
861
867
  return false;
862
868
  }
863
- return validRoles.includes(dataSourceCtxValue.user.roleId);
869
+ return dataSourceCtxValue.user.roleIds.includes(minRole);
864
870
  }
865
- if (!dataSourceCtxValue || dataSourceCtxValue.isUserLoading || !dataSourceCtxValue.user) {
871
+ if (!dataSourceCtxValue || dataSourceCtxValue.isUserLoading || !dataSourceCtxValue.user && canTriggerLogin) {
866
872
  return null;
867
873
  }
868
874
  if (!canUserViewPage()) {