@plasmicapp/react-web 0.2.148 → 0.2.150

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.
package/dist/all.d.ts CHANGED
@@ -20,8 +20,9 @@ declare function classNames$1(...args: Argument[]): string;
20
20
  interface PlasmicPageGuardProps {
21
21
  appId: string;
22
22
  authorizeEndpoint: string;
23
+ minRole: string;
24
+ canTriggerLogin: boolean;
23
25
  children: React__default.ReactNode;
24
- validRoles: string[];
25
26
  }
26
27
  declare function PlasmicPageGuard(props: PlasmicPageGuardProps): {} | null | undefined;
27
28
 
@@ -309,17 +310,21 @@ interface PlasmicDataSourceContextValue {
309
310
  userAuthToken?: string;
310
311
  isUserLoading?: boolean;
311
312
  user?: {
312
- id: string;
313
313
  email: string;
314
- roleId: string;
315
314
  properties: Record<string, unknown> | null;
315
+ roleId: string;
316
+ roleName: string;
317
+ roleIds: string[];
318
+ roleNames: string[];
316
319
  };
317
320
  }
318
321
  declare function useCurrentUser(): {
319
- id: string;
320
322
  email: string;
321
- roleId: string;
322
323
  properties: Record<string, unknown> | null;
324
+ roleId: string;
325
+ roleName: string;
326
+ roleIds: string[];
327
+ roleNames: string[];
323
328
  } | undefined;
324
329
  declare const PlasmicDataSourceContextProvider: React__default.Provider<PlasmicDataSourceContextValue | undefined>;
325
330
 
@@ -2,8 +2,9 @@ import React from "react";
2
2
  interface PlasmicPageGuardProps {
3
3
  appId: string;
4
4
  authorizeEndpoint: string;
5
+ minRole: string;
6
+ canTriggerLogin: boolean;
5
7
  children: React.ReactNode;
6
- validRoles: string[];
7
8
  }
8
9
  export declare function PlasmicPageGuard(props: PlasmicPageGuardProps): {} | null | undefined;
9
10
  export {};
@@ -847,14 +847,17 @@ function _triggerLogin() {
847
847
  function PlasmicPageGuard(props) {
848
848
  var appId = props.appId,
849
849
  authorizeEndpoint = props.authorizeEndpoint,
850
- validRoles = props.validRoles,
850
+ minRole = props.minRole,
851
+ canTriggerLogin = props.canTriggerLogin,
851
852
  children = props.children;
852
853
  var dataSourceCtxValue = dataSourcesContext.usePlasmicDataSourceContext();
853
854
  React__default.useEffect(function () {
854
- if (dataSourceCtxValue && "isUserLoading" in dataSourceCtxValue && !dataSourceCtxValue.isUserLoading && !dataSourceCtxValue.user) {
855
- triggerLogin(appId, authorizeEndpoint);
855
+ if (canTriggerLogin) {
856
+ if (dataSourceCtxValue && "isUserLoading" in dataSourceCtxValue && !dataSourceCtxValue.isUserLoading && !dataSourceCtxValue.user) {
857
+ triggerLogin(appId, authorizeEndpoint);
858
+ }
856
859
  }
857
- }, [dataSourceCtxValue, appId, authorizeEndpoint]);
860
+ }, [dataSourceCtxValue, appId, authorizeEndpoint, canTriggerLogin]);
858
861
  function canUserViewPage() {
859
862
  if (!dataSourceCtxValue) {
860
863
  return false;
@@ -862,12 +865,15 @@ function PlasmicPageGuard(props) {
862
865
  if (!dataSourceCtxValue.user) {
863
866
  return false;
864
867
  }
865
- if (!("roleId" in dataSourceCtxValue.user)) {
868
+ if (!("roleIds" in dataSourceCtxValue.user)) {
869
+ return false;
870
+ }
871
+ if (!Array.isArray(dataSourceCtxValue.user.roleIds)) {
866
872
  return false;
867
873
  }
868
- return validRoles.includes(dataSourceCtxValue.user.roleId);
874
+ return dataSourceCtxValue.user.roleIds.includes(minRole);
869
875
  }
870
- if (!dataSourceCtxValue || dataSourceCtxValue.isUserLoading || !dataSourceCtxValue.user) {
876
+ if (!dataSourceCtxValue || dataSourceCtxValue.isUserLoading || !dataSourceCtxValue.user && canTriggerLogin) {
871
877
  return null;
872
878
  }
873
879
  if (!canUserViewPage()) {