@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/react-web.esm.js
CHANGED
|
@@ -218,7 +218,7 @@ function triggerLogin(appId, authorizeEndpoint, redirectUri) {
|
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
220
|
function PlasmicPageGuard(props) {
|
|
221
|
-
var appId = props.appId, authorizeEndpoint = props.authorizeEndpoint, minRole = props.minRole, canTriggerLogin = props.canTriggerLogin, children = props.children;
|
|
221
|
+
var appId = props.appId, authorizeEndpoint = props.authorizeEndpoint, minRole = props.minRole, canTriggerLogin = props.canTriggerLogin, children = props.children, unauthorizedComp = props.unauthorizedComp;
|
|
222
222
|
var dataSourceCtxValue = usePlasmicDataSourceContext();
|
|
223
223
|
React__default.useEffect(function () {
|
|
224
224
|
if (canTriggerLogin) {
|
|
@@ -249,12 +249,24 @@ function PlasmicPageGuard(props) {
|
|
|
249
249
|
}
|
|
250
250
|
return dataSourceCtxValue.user.roleIds.includes(minRole);
|
|
251
251
|
}
|
|
252
|
+
/*
|
|
253
|
+
PlasmicPageGuard has three cases:
|
|
254
|
+
1. No value of dataSourceCtxValue, user is loading or a trigger login should be performed.
|
|
255
|
+
In this case, we don't want to render the children or the access denied message.
|
|
256
|
+
While the user is loading we look to see if don't have a user value as we can be in a
|
|
257
|
+
revalidate state.
|
|
258
|
+
2. The user doesn't have access to the page in which we show an access denied message.
|
|
259
|
+
3. The user has access to the page in which we render the children.
|
|
260
|
+
*/
|
|
252
261
|
if (!dataSourceCtxValue ||
|
|
253
|
-
dataSourceCtxValue.isUserLoading ||
|
|
262
|
+
(dataSourceCtxValue.isUserLoading && !dataSourceCtxValue.user) ||
|
|
254
263
|
(!dataSourceCtxValue.user && minRole && canTriggerLogin)) {
|
|
255
264
|
return null;
|
|
256
265
|
}
|
|
257
266
|
if (!canUserViewPage()) {
|
|
267
|
+
if (unauthorizedComp) {
|
|
268
|
+
return React__default.createElement(React__default.Fragment, null, unauthorizedComp);
|
|
269
|
+
}
|
|
258
270
|
return React__default.createElement("div", null, "You don't have access to this page");
|
|
259
271
|
}
|
|
260
272
|
return React__default.createElement(React__default.Fragment, null, children);
|