@plasmicapp/react-web 0.2.229 → 0.2.230
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 +1 -0
- package/dist/auth/PlasmicPageGuard.d.ts +1 -0
- package/dist/index.cjs.js +14 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/react-web.esm.js +14 -2
- package/dist/react-web.esm.js.map +1 -1
- package/package.json +2 -2
- package/skinny/dist/auth/PlasmicPageGuard.d.ts +1 -0
- package/skinny/dist/index.js +14 -2
- package/skinny/dist/index.js.map +1 -1
package/dist/all.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ interface PlasmicPageGuardProps {
|
|
|
24
24
|
minRole?: string;
|
|
25
25
|
canTriggerLogin: boolean;
|
|
26
26
|
children: React__default.ReactNode;
|
|
27
|
+
unauthorizedComp?: React__default.ReactNode;
|
|
27
28
|
}
|
|
28
29
|
declare function PlasmicPageGuard(props: PlasmicPageGuardProps): JSX.Element | null;
|
|
29
30
|
declare function withPlasmicPageGuard<P extends object>(WrappedComponent: React__default.ComponentType<P>, options: Omit<PlasmicPageGuardProps, "children">): React__default.FC<P>;
|
|
@@ -5,6 +5,7 @@ interface PlasmicPageGuardProps {
|
|
|
5
5
|
minRole?: string;
|
|
6
6
|
canTriggerLogin: boolean;
|
|
7
7
|
children: React.ReactNode;
|
|
8
|
+
unauthorizedComp?: React.ReactNode;
|
|
8
9
|
}
|
|
9
10
|
export declare function PlasmicPageGuard(props: PlasmicPageGuardProps): JSX.Element | null;
|
|
10
11
|
export declare function withPlasmicPageGuard<P extends object>(WrappedComponent: React.ComponentType<P>, options: Omit<PlasmicPageGuardProps, "children">): React.FC<P>;
|
package/dist/index.cjs.js
CHANGED
|
@@ -249,7 +249,7 @@ function triggerLogin(appId, authorizeEndpoint, redirectUri) {
|
|
|
249
249
|
});
|
|
250
250
|
}
|
|
251
251
|
function PlasmicPageGuard(props) {
|
|
252
|
-
var appId = props.appId, authorizeEndpoint = props.authorizeEndpoint, minRole = props.minRole, canTriggerLogin = props.canTriggerLogin, children = props.children;
|
|
252
|
+
var appId = props.appId, authorizeEndpoint = props.authorizeEndpoint, minRole = props.minRole, canTriggerLogin = props.canTriggerLogin, children = props.children, unauthorizedComp = props.unauthorizedComp;
|
|
253
253
|
var dataSourceCtxValue = dataSourcesContext.usePlasmicDataSourceContext();
|
|
254
254
|
React__default['default'].useEffect(function () {
|
|
255
255
|
if (canTriggerLogin) {
|
|
@@ -280,12 +280,24 @@ function PlasmicPageGuard(props) {
|
|
|
280
280
|
}
|
|
281
281
|
return dataSourceCtxValue.user.roleIds.includes(minRole);
|
|
282
282
|
}
|
|
283
|
+
/*
|
|
284
|
+
PlasmicPageGuard has three cases:
|
|
285
|
+
1. No value of dataSourceCtxValue, user is loading or a trigger login should be performed.
|
|
286
|
+
In this case, we don't want to render the children or the access denied message.
|
|
287
|
+
While the user is loading we look to see if don't have a user value as we can be in a
|
|
288
|
+
revalidate state.
|
|
289
|
+
2. The user doesn't have access to the page in which we show an access denied message.
|
|
290
|
+
3. The user has access to the page in which we render the children.
|
|
291
|
+
*/
|
|
283
292
|
if (!dataSourceCtxValue ||
|
|
284
|
-
dataSourceCtxValue.isUserLoading ||
|
|
293
|
+
(dataSourceCtxValue.isUserLoading && !dataSourceCtxValue.user) ||
|
|
285
294
|
(!dataSourceCtxValue.user && minRole && canTriggerLogin)) {
|
|
286
295
|
return null;
|
|
287
296
|
}
|
|
288
297
|
if (!canUserViewPage()) {
|
|
298
|
+
if (unauthorizedComp) {
|
|
299
|
+
return React__default['default'].createElement(React__default['default'].Fragment, null, unauthorizedComp);
|
|
300
|
+
}
|
|
289
301
|
return React__default['default'].createElement("div", null, "You don't have access to this page");
|
|
290
302
|
}
|
|
291
303
|
return React__default['default'].createElement(React__default['default'].Fragment, null, children);
|