@lanaqi/rsr 0.0.1-rc.0 → 0.0.2
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/README.md +8 -2
- package/dist/index.js +113 -103
- package/dist/support/aaa.d.ts +4 -6
- package/dist/support/signature.d.ts +2 -3
- package/dist/support/user.d.ts +6 -7
- package/package.json +16 -10
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ React 安全路由器
|
|
|
4
4
|
|
|
5
5
|
# 框架说明
|
|
6
6
|
|
|
7
|
-
rsr 是 react security router 的简写,一个基于 react router
|
|
7
|
+
rsr 是 react security router 的简写,一个基于 react router 实现纯前端路由级别控制的安全框架。
|
|
8
8
|
|
|
9
9
|
功能简介:
|
|
10
10
|
|
|
@@ -15,7 +15,7 @@ rsr 是 react security router 的简写,一个基于 react router 实现路由
|
|
|
15
15
|
|
|
16
16
|
# 版本兼容
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
注意:目前只兼容 react router v6 & v7 版本,其它的版本,暂时不考虑兼容。
|
|
19
19
|
|
|
20
20
|
# 简单例子
|
|
21
21
|
|
|
@@ -47,3 +47,9 @@ export default withSecurityBlocker(Root, bundler => {
|
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
```
|
|
50
|
+
|
|
51
|
+
# 其它例子
|
|
52
|
+
|
|
53
|
+
基于 Modern.js 的例子:https://github.com/lanaqi-opensource/rsr-demo
|
|
54
|
+
|
|
55
|
+
基于 react-router-dom 的例子:https://github.com/lanaqi-opensource/rsr6-demo
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { matchPath, useBlocker, useLocation, useNavigate } from "react-router-dom";
|
|
2
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
4
4
|
var common_AccessDecision = /*#__PURE__*/ function(AccessDecision) {
|
|
5
5
|
AccessDecision["notResource"] = "notResource";
|
|
6
6
|
AccessDecision["notAuthentication"] = "notAuthentication";
|
|
@@ -431,10 +431,8 @@ class SimpleStorer {
|
|
|
431
431
|
const authenticationStr = this.aaaStorage.getItem(this.authenticationKey);
|
|
432
432
|
if (authenticationStr) {
|
|
433
433
|
const authenticationObj = JSON.parse(authenticationStr);
|
|
434
|
-
if ('boolean' == typeof authenticationObj.authenticated)
|
|
435
|
-
|
|
436
|
-
return new SimpleAuthentication(authenticationObj);
|
|
437
|
-
}
|
|
434
|
+
if ('boolean' == typeof authenticationObj.authenticated) if (void 0 !== authenticationObj.permissions && Array.isArray(authenticationObj.permissions)) return new SimpleUser(authenticationObj);
|
|
435
|
+
else return new SimpleAuthentication(authenticationObj);
|
|
438
436
|
}
|
|
439
437
|
}
|
|
440
438
|
verifyAuthentication(recorder, authentication) {
|
|
@@ -523,11 +521,11 @@ class SimpleMatcher {
|
|
|
523
521
|
...pattern,
|
|
524
522
|
path: basename + pattern.path
|
|
525
523
|
};
|
|
526
|
-
const pm =
|
|
524
|
+
const pm = matchPath(matchPattern, path.pathname);
|
|
527
525
|
if (pm) return true;
|
|
528
526
|
}
|
|
529
527
|
else for (const pattern of patterns){
|
|
530
|
-
const pm =
|
|
528
|
+
const pm = matchPath(pattern, path.pathname);
|
|
531
529
|
if (pm) return true;
|
|
532
530
|
}
|
|
533
531
|
return false;
|
|
@@ -678,10 +676,7 @@ class BehaveHandler {
|
|
|
678
676
|
return common_AccessBehave.doNothing;
|
|
679
677
|
}
|
|
680
678
|
errorDecision(context, decision) {
|
|
681
|
-
if (this._config.errorDecisionFunc)
|
|
682
|
-
this._config.errorDecisionFunc(context, decision);
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
679
|
+
if (this._config.errorDecisionFunc) return void this._config.errorDecisionFunc(context, decision);
|
|
685
680
|
if (decision === common_AccessDecision.notSignature) return;
|
|
686
681
|
switch(decision){
|
|
687
682
|
case common_AccessDecision.notResource:
|
|
@@ -1304,101 +1299,103 @@ class AccessGuarderBuilder {
|
|
|
1304
1299
|
};
|
|
1305
1300
|
}
|
|
1306
1301
|
}
|
|
1307
|
-
const SecurityContext = /*#__PURE__*/
|
|
1302
|
+
const SecurityContext = /*#__PURE__*/ createContext(null);
|
|
1308
1303
|
const useSecurityContext = ()=>{
|
|
1309
|
-
const sc =
|
|
1304
|
+
const sc = useContext(SecurityContext);
|
|
1310
1305
|
if (!sc) throw new Error('安全上下文为空,必须使用安全提供者包裹组件来设置安全上下文');
|
|
1311
1306
|
return sc;
|
|
1312
1307
|
};
|
|
1313
1308
|
function SecurityProvider({ children, bundler }) {
|
|
1314
|
-
const navigate =
|
|
1315
|
-
const provide =
|
|
1309
|
+
const navigate = useNavigate();
|
|
1310
|
+
const provide = useMemo(()=>bundler(new AccessGuarderBuilder().navigate(navigate)), [
|
|
1316
1311
|
bundler,
|
|
1317
1312
|
navigate
|
|
1318
1313
|
]);
|
|
1319
|
-
return /*#__PURE__*/
|
|
1314
|
+
return /*#__PURE__*/ jsx(SecurityContext.Provider, {
|
|
1320
1315
|
value: provide,
|
|
1321
1316
|
children: children
|
|
1322
1317
|
});
|
|
1323
1318
|
}
|
|
1324
1319
|
function SecurityBlocker({ children }) {
|
|
1325
1320
|
const { context, manager, guarder } = useSecurityContext();
|
|
1326
|
-
if (manager.isDisabled()) return /*#__PURE__*/
|
|
1321
|
+
if (manager.isDisabled()) return /*#__PURE__*/ jsx(Fragment, {
|
|
1327
1322
|
children: children
|
|
1328
1323
|
});
|
|
1329
|
-
const blocker =
|
|
1330
|
-
const [guarded, setGuarded] =
|
|
1331
|
-
const [nextPath, setNextPath] =
|
|
1332
|
-
const [firstAccess, setFirstAccess] =
|
|
1333
|
-
const [firstHandle, setFirstHandle] =
|
|
1334
|
-
const [
|
|
1335
|
-
const [
|
|
1336
|
-
const [beforeDecision, setBeforeDecision] =
|
|
1337
|
-
const [currentDecision, setCurrentDecision] =
|
|
1338
|
-
const [
|
|
1339
|
-
|
|
1340
|
-
|
|
1324
|
+
const blocker = useBlocker(({ currentLocation, nextLocation })=>currentLocation.pathname !== nextLocation.pathname);
|
|
1325
|
+
const [guarded, setGuarded] = useState(false);
|
|
1326
|
+
const [nextPath, setNextPath] = useState(useLocation());
|
|
1327
|
+
const [firstAccess, setFirstAccess] = useState(true);
|
|
1328
|
+
const [firstHandle, setFirstHandle] = useState(true);
|
|
1329
|
+
const [countSignature, setCountSignature] = useState(1);
|
|
1330
|
+
const [handledDecision, setHandledDecision] = useState(false);
|
|
1331
|
+
const [beforeDecision, setBeforeDecision] = useState(void 0);
|
|
1332
|
+
const [currentDecision, setCurrentDecision] = useState(void 0);
|
|
1333
|
+
const [securityBlock, setSecurityBlock] = useState(false);
|
|
1334
|
+
const [executableBlocked, setExecutableBlocked] = useState(true);
|
|
1335
|
+
useEffect(()=>{
|
|
1336
|
+
if ('blocked' === blocker.state && executableBlocked) {
|
|
1337
|
+
let isProceed;
|
|
1341
1338
|
const recorder = context.getRecorder();
|
|
1342
1339
|
const stayPath = recorder.getAllowPath();
|
|
1343
1340
|
const blockPath = blocker.location;
|
|
1344
1341
|
let guardBlocked = false;
|
|
1345
|
-
if (
|
|
1342
|
+
if (securityBlock) guardBlocked = guarder.guardBlock(blockPath);
|
|
1346
1343
|
if (guardBlocked) {
|
|
1347
|
-
|
|
1348
|
-
setNextPath(blockPath);
|
|
1349
|
-
setHandleDecision(false);
|
|
1344
|
+
setHandledDecision(false);
|
|
1350
1345
|
setCurrentDecision(void 0);
|
|
1346
|
+
isProceed = false;
|
|
1351
1347
|
} else {
|
|
1352
1348
|
if (!beforeDecision) guarder.guardBefore(blockPath);
|
|
1353
1349
|
const blockedDecision = guarder.guardDecision(blockPath);
|
|
1354
|
-
|
|
1355
|
-
const isDiff = !!stayPath && stayPath.pathname !== blockPath.pathname;
|
|
1356
|
-
if (isDiff) guarder.permitBefore(stayPath, blockPath);
|
|
1357
|
-
blocker.proceed();
|
|
1358
|
-
if (isDiff) guarder.permitAfter(stayPath, blockPath);
|
|
1359
|
-
} else blocker.reset();
|
|
1360
|
-
setNextPath(blockPath);
|
|
1361
|
-
setHandleDecision(true);
|
|
1350
|
+
setHandledDecision(true);
|
|
1362
1351
|
setCurrentDecision(blockedDecision);
|
|
1352
|
+
isProceed = blockedDecision === common_AccessDecision.allowAccess;
|
|
1363
1353
|
}
|
|
1354
|
+
setNextPath(blockPath);
|
|
1355
|
+
setExecutableBlocked(false);
|
|
1356
|
+
if (isProceed) {
|
|
1357
|
+
const isDiff = !!stayPath && stayPath.pathname !== blockPath.pathname;
|
|
1358
|
+
if (isDiff) guarder.permitBefore(stayPath, blockPath);
|
|
1359
|
+
blocker.proceed();
|
|
1360
|
+
if (isDiff) guarder.permitAfter(stayPath, blockPath);
|
|
1361
|
+
} else blocker.reset();
|
|
1364
1362
|
} else if ('unblocked' === blocker.state) {
|
|
1365
|
-
if (
|
|
1363
|
+
if (handledDecision && currentDecision) {
|
|
1366
1364
|
let navNext;
|
|
1367
1365
|
const behave = guarder.guardHandle(currentDecision, beforeDecision);
|
|
1368
1366
|
switch(behave){
|
|
1369
1367
|
case common_AccessBehave.reDecision:
|
|
1370
1368
|
setBeforeDecision(currentDecision);
|
|
1371
|
-
|
|
1369
|
+
setSecurityBlock(false);
|
|
1372
1370
|
navNext = true;
|
|
1373
1371
|
break;
|
|
1374
1372
|
case common_AccessBehave.goNavigate:
|
|
1375
1373
|
setBeforeDecision(void 0);
|
|
1376
1374
|
navNext = false;
|
|
1377
|
-
|
|
1375
|
+
setSecurityBlock(false);
|
|
1378
1376
|
break;
|
|
1379
1377
|
case common_AccessBehave.doNothing:
|
|
1380
1378
|
default:
|
|
1381
1379
|
setBeforeDecision(void 0);
|
|
1382
1380
|
navNext = false;
|
|
1383
|
-
|
|
1381
|
+
setSecurityBlock(true);
|
|
1384
1382
|
break;
|
|
1385
1383
|
}
|
|
1386
|
-
if (firstHandle && currentDecision === common_AccessDecision.notSignature && behave === common_AccessBehave.reDecision) {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
setCurrentDecision(common_AccessDecision.accessDenied);
|
|
1392
|
-
} else {
|
|
1393
|
-
const signDecision = guarder.guardDecision(nextPath);
|
|
1394
|
-
setHandleDecision(true);
|
|
1395
|
-
setBeforeDecision(void 0);
|
|
1396
|
-
setCurrentDecision(signDecision);
|
|
1397
|
-
setFirstSignature(firstSignature + 1);
|
|
1398
|
-
}
|
|
1384
|
+
if (firstHandle && currentDecision === common_AccessDecision.notSignature && behave === common_AccessBehave.reDecision) if (countSignature >= 3) {
|
|
1385
|
+
setFirstHandle(false);
|
|
1386
|
+
setBeforeDecision(common_AccessDecision.notSignature);
|
|
1387
|
+
setHandledDecision(true);
|
|
1388
|
+
setCurrentDecision(common_AccessDecision.accessDenied);
|
|
1399
1389
|
} else {
|
|
1390
|
+
const signDecision = guarder.guardDecision(nextPath);
|
|
1391
|
+
setHandledDecision(true);
|
|
1392
|
+
setBeforeDecision(void 0);
|
|
1393
|
+
setCurrentDecision(signDecision);
|
|
1394
|
+
setCountSignature(countSignature + 1);
|
|
1395
|
+
}
|
|
1396
|
+
else {
|
|
1400
1397
|
setFirstHandle(false);
|
|
1401
|
-
|
|
1398
|
+
setHandledDecision(false);
|
|
1402
1399
|
setCurrentDecision(void 0);
|
|
1403
1400
|
if (navNext) context.getNavigator().navigate(nextPath);
|
|
1404
1401
|
else {
|
|
@@ -1410,9 +1407,10 @@ function SecurityBlocker({ children }) {
|
|
|
1410
1407
|
guarder.guardBefore(nextPath);
|
|
1411
1408
|
const firstDecision = guarder.guardDecision(nextPath);
|
|
1412
1409
|
setFirstAccess(false);
|
|
1413
|
-
|
|
1410
|
+
setHandledDecision(true);
|
|
1414
1411
|
setCurrentDecision(firstDecision);
|
|
1415
1412
|
}
|
|
1413
|
+
if (!executableBlocked) setExecutableBlocked(true);
|
|
1416
1414
|
}
|
|
1417
1415
|
}, [
|
|
1418
1416
|
blocker,
|
|
@@ -1421,21 +1419,22 @@ function SecurityBlocker({ children }) {
|
|
|
1421
1419
|
nextPath,
|
|
1422
1420
|
firstAccess,
|
|
1423
1421
|
firstHandle,
|
|
1424
|
-
|
|
1425
|
-
|
|
1422
|
+
countSignature,
|
|
1423
|
+
handledDecision,
|
|
1426
1424
|
beforeDecision,
|
|
1427
1425
|
currentDecision,
|
|
1428
|
-
|
|
1426
|
+
securityBlock,
|
|
1427
|
+
executableBlocked
|
|
1429
1428
|
]);
|
|
1430
|
-
if (!guarded) return /*#__PURE__*/
|
|
1431
|
-
return /*#__PURE__*/
|
|
1429
|
+
if (!guarded) return /*#__PURE__*/ jsx(Fragment, {});
|
|
1430
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
1432
1431
|
children: children
|
|
1433
1432
|
});
|
|
1434
1433
|
}
|
|
1435
|
-
const withSecurityBlocker = (Component, bundler)=>()=>/*#__PURE__*/
|
|
1434
|
+
const withSecurityBlocker = (Component, bundler)=>()=>/*#__PURE__*/ jsx(SecurityProvider, {
|
|
1436
1435
|
bundler: bundler,
|
|
1437
|
-
children: /*#__PURE__*/
|
|
1438
|
-
children: /*#__PURE__*/
|
|
1436
|
+
children: /*#__PURE__*/ jsx(SecurityBlocker, {
|
|
1437
|
+
children: /*#__PURE__*/ jsx(Component, {})
|
|
1439
1438
|
})
|
|
1440
1439
|
});
|
|
1441
1440
|
const useObtainAuthentication = ()=>{
|
|
@@ -1502,7 +1501,7 @@ const useDeleteAuthorization = ()=>{
|
|
|
1502
1501
|
}
|
|
1503
1502
|
};
|
|
1504
1503
|
};
|
|
1505
|
-
const useSaveAuthentication = (
|
|
1504
|
+
const useSaveAuthentication = (redirect = '')=>{
|
|
1506
1505
|
const { context } = useSecurityContext();
|
|
1507
1506
|
const recorder = context.getRecorder();
|
|
1508
1507
|
const storer = context.getStorer();
|
|
@@ -1511,14 +1510,14 @@ const useSaveAuthentication = (navigate = false, redirect = '/')=>{
|
|
|
1511
1510
|
storer.saveAuthentication(recorder, datasheet);
|
|
1512
1511
|
recorder.clearAccessAuthentication();
|
|
1513
1512
|
recorder.clearAccessAuthorization();
|
|
1514
|
-
if (
|
|
1513
|
+
if ('' !== redirect) {
|
|
1515
1514
|
const path = recorder.getOriginPath();
|
|
1516
1515
|
if (path) navigator.navigate(path);
|
|
1517
1516
|
else navigator.navigate(redirect);
|
|
1518
1517
|
}
|
|
1519
1518
|
};
|
|
1520
1519
|
};
|
|
1521
|
-
const useSaveAuthorization = (
|
|
1520
|
+
const useSaveAuthorization = (redirect = '')=>{
|
|
1522
1521
|
const { context } = useSecurityContext();
|
|
1523
1522
|
const recorder = context.getRecorder();
|
|
1524
1523
|
const storer = context.getStorer();
|
|
@@ -1526,7 +1525,7 @@ const useSaveAuthorization = (navigate = false, redirect = '/')=>{
|
|
|
1526
1525
|
return (datasheet)=>{
|
|
1527
1526
|
storer.saveAuthorization(recorder, datasheet);
|
|
1528
1527
|
recorder.clearAccessAuthorization();
|
|
1529
|
-
if (
|
|
1528
|
+
if ('' !== redirect) {
|
|
1530
1529
|
const path = recorder.getOriginPath();
|
|
1531
1530
|
if (path) navigator.navigate(path);
|
|
1532
1531
|
else navigator.navigate(redirect);
|
|
@@ -1550,7 +1549,7 @@ const useHavePermission = ()=>{
|
|
|
1550
1549
|
return have;
|
|
1551
1550
|
};
|
|
1552
1551
|
};
|
|
1553
|
-
const useSaveSignature = (
|
|
1552
|
+
const useSaveSignature = (redirect = '/')=>{
|
|
1554
1553
|
const { context } = useSecurityContext();
|
|
1555
1554
|
const recorder = context.getRecorder();
|
|
1556
1555
|
const storer = context.getStorer();
|
|
@@ -1559,10 +1558,8 @@ const useSaveSignature = (navigate = true, redirect = '/')=>{
|
|
|
1559
1558
|
let target;
|
|
1560
1559
|
target = path ? path : recorder.getOriginPath();
|
|
1561
1560
|
if (target) storer.saveSignature(recorder, target);
|
|
1562
|
-
if (navigate)
|
|
1563
|
-
|
|
1564
|
-
else navigator.navigate(redirect);
|
|
1565
|
-
}
|
|
1561
|
+
if ('' !== redirect) if (target) navigator.navigate(target);
|
|
1562
|
+
else navigator.navigate(redirect);
|
|
1566
1563
|
};
|
|
1567
1564
|
};
|
|
1568
1565
|
const useDeleteSignature = ()=>{
|
|
@@ -1591,7 +1588,7 @@ const usePurgeSignature = ()=>{
|
|
|
1591
1588
|
const recorder = context.getRecorder();
|
|
1592
1589
|
const storer = context.getStorer();
|
|
1593
1590
|
const path = recorder.getCurrentPath();
|
|
1594
|
-
|
|
1591
|
+
useEffect(()=>()=>{
|
|
1595
1592
|
if (path) storer.removeSignature(recorder, path);
|
|
1596
1593
|
}, [
|
|
1597
1594
|
recorder,
|
|
@@ -1599,7 +1596,7 @@ const usePurgeSignature = ()=>{
|
|
|
1599
1596
|
path
|
|
1600
1597
|
]);
|
|
1601
1598
|
};
|
|
1602
|
-
const useLogout = (
|
|
1599
|
+
const useLogout = (cRedirect = '/', pRedirect = '/')=>{
|
|
1603
1600
|
const { context } = useSecurityContext();
|
|
1604
1601
|
const recorder = context.getRecorder();
|
|
1605
1602
|
const storer = context.getStorer();
|
|
@@ -1610,7 +1607,7 @@ const useLogout = (navigate = true, redirect = '/')=>{
|
|
|
1610
1607
|
storer.deleteSignature(recorder);
|
|
1611
1608
|
recorder.clearAccessAuthentication();
|
|
1612
1609
|
recorder.clearAccessAuthorization();
|
|
1613
|
-
if (
|
|
1610
|
+
if ("" !== cRedirect) navigator.navigate(cRedirect);
|
|
1614
1611
|
const parent = context.getParent();
|
|
1615
1612
|
if (parent) {
|
|
1616
1613
|
const p_recorder = parent.getRecorder();
|
|
@@ -1621,21 +1618,30 @@ const useLogout = (navigate = true, redirect = '/')=>{
|
|
|
1621
1618
|
p_storer.deleteSignature(p_recorder);
|
|
1622
1619
|
p_recorder.clearAccessAuthentication();
|
|
1623
1620
|
p_recorder.clearAccessAuthorization();
|
|
1624
|
-
if (
|
|
1621
|
+
if ("" !== pRedirect) p_navigator.navigate(pRedirect);
|
|
1625
1622
|
}
|
|
1626
1623
|
};
|
|
1627
1624
|
};
|
|
1628
|
-
const useLogin = (
|
|
1625
|
+
const useLogin = (cRedirect = '/', pRedirect = '/')=>{
|
|
1629
1626
|
const { context } = useSecurityContext();
|
|
1630
1627
|
const recorder = context.getRecorder();
|
|
1631
1628
|
const storer = context.getStorer();
|
|
1632
1629
|
const navigator = context.getNavigator();
|
|
1633
|
-
|
|
1630
|
+
useEffect(()=>{
|
|
1634
1631
|
const isAuthentication = recorder.existAccessAuthentication() || !!storer.loadAuthentication(recorder);
|
|
1635
|
-
if (
|
|
1632
|
+
if (isAuthentication) {
|
|
1633
|
+
const e_parent = context.getParent();
|
|
1634
|
+
if (e_parent && "" !== pRedirect) {
|
|
1635
|
+
const p_navigator = e_parent.getNavigator();
|
|
1636
|
+
p_navigator.navigate(pRedirect);
|
|
1637
|
+
} else if ("" !== cRedirect) {
|
|
1638
|
+
const path = recorder.getOriginPath();
|
|
1639
|
+
if (path) navigator.navigate(path);
|
|
1640
|
+
else navigator.navigate(cRedirect);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1636
1643
|
}, [
|
|
1637
|
-
|
|
1638
|
-
redirect,
|
|
1644
|
+
cRedirect,
|
|
1639
1645
|
recorder,
|
|
1640
1646
|
storer,
|
|
1641
1647
|
navigator
|
|
@@ -1644,17 +1650,21 @@ const useLogin = (logined = false, navigate = true, redirect = '/')=>{
|
|
|
1644
1650
|
storer.saveAuthentication(recorder, datasheet);
|
|
1645
1651
|
recorder.clearAccessAuthentication();
|
|
1646
1652
|
recorder.clearAccessAuthorization();
|
|
1647
|
-
|
|
1653
|
+
const r_parent = context.getParent();
|
|
1654
|
+
if (r_parent && "" !== pRedirect) {
|
|
1655
|
+
const p_navigator = r_parent.getNavigator();
|
|
1656
|
+
p_navigator.navigate(pRedirect);
|
|
1657
|
+
} else if ("" !== cRedirect) {
|
|
1648
1658
|
const path = recorder.getOriginPath();
|
|
1649
1659
|
if (path) navigator.navigate(path);
|
|
1650
|
-
else navigator.navigate(
|
|
1660
|
+
else navigator.navigate(cRedirect);
|
|
1651
1661
|
}
|
|
1652
1662
|
};
|
|
1653
1663
|
};
|
|
1654
1664
|
const useCustomBlocker = (handler)=>{
|
|
1655
1665
|
const { manager } = useSecurityContext();
|
|
1656
1666
|
const blocker = manager.getBlocker();
|
|
1657
|
-
|
|
1667
|
+
useEffect(()=>{
|
|
1658
1668
|
blocker.register(handler);
|
|
1659
1669
|
return ()=>{
|
|
1660
1670
|
blocker.unregister(handler);
|
|
@@ -1666,11 +1676,10 @@ const useCustomBlocker = (handler)=>{
|
|
|
1666
1676
|
};
|
|
1667
1677
|
const useSecurityBlocker = (recover = true)=>{
|
|
1668
1678
|
const { context, manager } = useSecurityContext();
|
|
1669
|
-
const
|
|
1670
|
-
const [
|
|
1671
|
-
const [
|
|
1672
|
-
const
|
|
1673
|
-
const proceed = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
|
|
1679
|
+
const [path, setPath] = useState();
|
|
1680
|
+
const [jump, setJump] = useState(false);
|
|
1681
|
+
const [blocked, setBlocked] = useState(false);
|
|
1682
|
+
const proceed = useCallback(()=>{
|
|
1674
1683
|
if (path) {
|
|
1675
1684
|
setJump(true);
|
|
1676
1685
|
if (recover) {
|
|
@@ -1684,12 +1693,12 @@ const useSecurityBlocker = (recover = true)=>{
|
|
|
1684
1693
|
path,
|
|
1685
1694
|
recover
|
|
1686
1695
|
]);
|
|
1687
|
-
const reset =
|
|
1696
|
+
const reset = useCallback(()=>{
|
|
1688
1697
|
setPath(void 0);
|
|
1689
1698
|
setJump(false);
|
|
1690
1699
|
setBlocked(false);
|
|
1691
1700
|
}, []);
|
|
1692
|
-
const handler =
|
|
1701
|
+
const handler = useCallback((context, currentPath, currentResource)=>{
|
|
1693
1702
|
setJump(false);
|
|
1694
1703
|
if (jump) return false;
|
|
1695
1704
|
setPath(currentPath);
|
|
@@ -1698,7 +1707,8 @@ const useSecurityBlocker = (recover = true)=>{
|
|
|
1698
1707
|
}, [
|
|
1699
1708
|
jump
|
|
1700
1709
|
]);
|
|
1701
|
-
|
|
1710
|
+
const blocker = manager.getBlocker();
|
|
1711
|
+
useEffect(()=>{
|
|
1702
1712
|
blocker.register(handler);
|
|
1703
1713
|
return ()=>{
|
|
1704
1714
|
blocker.unregister(handler);
|
|
@@ -1717,14 +1727,14 @@ const useSecurityBlocker = (recover = true)=>{
|
|
|
1717
1727
|
function HavePermission({ children, term }) {
|
|
1718
1728
|
const havePermission = useHavePermission();
|
|
1719
1729
|
const have = havePermission(term);
|
|
1720
|
-
if (!have) return /*#__PURE__*/
|
|
1721
|
-
return /*#__PURE__*/
|
|
1730
|
+
if (!have) return /*#__PURE__*/ jsx(Fragment, {});
|
|
1731
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
1722
1732
|
children: children
|
|
1723
1733
|
});
|
|
1724
1734
|
}
|
|
1725
|
-
const withHavePermission = (Component, term)=>()=>/*#__PURE__*/
|
|
1735
|
+
const withHavePermission = (Component, term)=>()=>/*#__PURE__*/ jsx(HavePermission, {
|
|
1726
1736
|
term: term,
|
|
1727
|
-
children: /*#__PURE__*/
|
|
1737
|
+
children: /*#__PURE__*/ jsx(Component, {})
|
|
1728
1738
|
});
|
|
1729
1739
|
class MicroAppAddon extends AbstractAddon {
|
|
1730
1740
|
static HIERARCHY_JOIN_IGNORE = 'ignore';
|
package/dist/support/aaa.d.ts
CHANGED
|
@@ -17,13 +17,11 @@ export declare const useDeleteAuthentication: () => (() => void);
|
|
|
17
17
|
export declare const useDeleteAuthorization: () => (() => void);
|
|
18
18
|
/**
|
|
19
19
|
* 保存认证钩子
|
|
20
|
-
* @param
|
|
21
|
-
* @param redirect 重定向路径(如果不存在原始路径时使用)
|
|
20
|
+
* @param redirect 重定向路径,当为空字符串时不进行重定向,默认:空(如果不存在原始路径时使用)
|
|
22
21
|
*/
|
|
23
|
-
export declare const useSaveAuthentication: <Datasheet>(
|
|
22
|
+
export declare const useSaveAuthentication: <Datasheet>(redirect?: string) => ((datasheet: AccessDatasheet<AuthenticationDatasheet<Datasheet>>) => void);
|
|
24
23
|
/**
|
|
25
24
|
* 保存授权钩子
|
|
26
|
-
* @param
|
|
27
|
-
* @param redirect 重定向路径(如果不存在原始路径时使用)
|
|
25
|
+
* @param redirect 重定向路径,当为空字符串时不进行重定向,默认:空(如果不存在原始路径时使用)
|
|
28
26
|
*/
|
|
29
|
-
export declare const useSaveAuthorization: <Datasheet>(
|
|
27
|
+
export declare const useSaveAuthorization: <Datasheet>(redirect?: string) => ((datasheet: AccessDatasheet<AuthorizationDatasheet<Datasheet>>) => void);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { AccessPath } from '../access';
|
|
2
2
|
/**
|
|
3
3
|
* 保存签名钩子
|
|
4
|
-
* @param
|
|
5
|
-
* @param redirect 重定向路径(如果不存在原始路径时使用)
|
|
4
|
+
* @param redirect 重定向路径,当为空字符串时不进行重定向,默认:'/'(如果不存在原始路径时使用)
|
|
6
5
|
*/
|
|
7
|
-
export declare const useSaveSignature: (
|
|
6
|
+
export declare const useSaveSignature: (redirect?: string) => ((path?: AccessPath) => void);
|
|
8
7
|
/**
|
|
9
8
|
* 删除签名钩子
|
|
10
9
|
*/
|
package/dist/support/user.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { AccessDatasheet, UserDatasheet } from '../access';
|
|
2
2
|
/**
|
|
3
3
|
* 登出钩子
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
4
|
+
* @param cRedirect 当前重定向路径,当为空字符串时不进行重定向,默认:'/'
|
|
5
|
+
* @param pRedirect 父级重定向路径,当为空字符串时不进行重定向,默认:'/'(如果存在父级时才会生效)
|
|
6
6
|
*/
|
|
7
|
-
export declare const useLogout: (
|
|
7
|
+
export declare const useLogout: (cRedirect?: string, pRedirect?: string) => (() => void);
|
|
8
8
|
/**
|
|
9
9
|
* 登入钩子
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @param redirect 重定向路径(如果不存在原始路径时使用)
|
|
10
|
+
* @param cRedirect 当前重定向路径,当为空字符串时不进行重定向,默认:'/'(如果不存在原始路径时使用)
|
|
11
|
+
* @param pRedirect 父级重定向路径,当为空字符串时不进行重定向,默认:'/'(如果存在父级时才会生效)
|
|
13
12
|
*/
|
|
14
|
-
export declare const useLogin: <Datasheet>(
|
|
13
|
+
export declare const useLogin: <Datasheet>(cRedirect?: string, pRedirect?: string) => ((datasheet: AccessDatasheet<UserDatasheet<Datasheet>>) => void);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lanaqi/rsr",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -27,6 +27,12 @@
|
|
|
27
27
|
"react-router-dom",
|
|
28
28
|
"modern-js",
|
|
29
29
|
"modernjs",
|
|
30
|
+
"auth",
|
|
31
|
+
"authentication",
|
|
32
|
+
"authorization",
|
|
33
|
+
"csr",
|
|
34
|
+
"rsr",
|
|
35
|
+
"纯前端",
|
|
30
36
|
"安全",
|
|
31
37
|
"鉴权",
|
|
32
38
|
"守护",
|
|
@@ -48,19 +54,19 @@
|
|
|
48
54
|
},
|
|
49
55
|
"devDependencies": {
|
|
50
56
|
"@biomejs/biome": "^1.9.4",
|
|
51
|
-
"@rsbuild/plugin-react": "^1.
|
|
52
|
-
"@rslib/core": "
|
|
53
|
-
"@types/react": "^
|
|
54
|
-
"@types/react-dom": "^
|
|
55
|
-
"react": "^
|
|
56
|
-
"react-dom": "^
|
|
57
|
-
"react-router-dom": "^
|
|
58
|
-
"typescript": "^5.
|
|
57
|
+
"@rsbuild/plugin-react": "^1.4.1",
|
|
58
|
+
"@rslib/core": "0.15.0",
|
|
59
|
+
"@types/react": "^19.2.2",
|
|
60
|
+
"@types/react-dom": "^19.2.1",
|
|
61
|
+
"react": "^19.2.0",
|
|
62
|
+
"react-dom": "^19.2.0",
|
|
63
|
+
"react-router-dom": "^7.9.4",
|
|
64
|
+
"typescript": "^5.9.3"
|
|
59
65
|
},
|
|
60
66
|
"peerDependencies": {
|
|
61
67
|
"react": ">=17.0.0",
|
|
62
68
|
"react-dom": ">=17.0.0",
|
|
63
|
-
"react-router-dom": "^6.0.0"
|
|
69
|
+
"react-router-dom": "^6.0.0 || ^7.0.0"
|
|
64
70
|
},
|
|
65
71
|
"private": false,
|
|
66
72
|
"publishConfig": {
|