react-redux-django-auth 1.3.8 → 1.3.9
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/index.js +37 -79
- package/dist/index.mjs +20 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1300,7 +1300,8 @@ var import_react5 = require("react");
|
|
|
1300
1300
|
var import_react_redux5 = require("react-redux");
|
|
1301
1301
|
var useAuthicatedUser = function(apiURL, location) {
|
|
1302
1302
|
var dispatch = (0, import_react_redux5.useDispatch)();
|
|
1303
|
-
var _ref = _sliced_to_array((0, import_react5.useState)(true), 2),
|
|
1303
|
+
var _ref = _sliced_to_array((0, import_react5.useState)(true), 2), isAuthLoading = _ref[0], setIsAuthLoading = _ref[1];
|
|
1304
|
+
var _ref1 = _sliced_to_array((0, import_react5.useState)(false), 2), isUserLoading = _ref1[0], setIsUserLoading = _ref1[1];
|
|
1304
1305
|
var isAuthenticated = (0, import_react_redux5.useSelector)(function(state) {
|
|
1305
1306
|
return state.auth.isAuthenticated;
|
|
1306
1307
|
});
|
|
@@ -1311,35 +1312,19 @@ var useAuthicatedUser = function(apiURL, location) {
|
|
|
1311
1312
|
return state.auth.user;
|
|
1312
1313
|
});
|
|
1313
1314
|
(0, import_react5.useEffect)(function() {
|
|
1314
|
-
var
|
|
1315
|
+
var runAuthCheck = function() {
|
|
1315
1316
|
return _async_to_generator(function() {
|
|
1316
1317
|
return _ts_generator(this, function(_state) {
|
|
1317
1318
|
switch(_state.label){
|
|
1318
1319
|
case 0:
|
|
1319
|
-
|
|
1320
|
-
_state.label = 1;
|
|
1321
|
-
case 1:
|
|
1322
|
-
_state.trys.push([
|
|
1323
|
-
1,
|
|
1324
|
-
,
|
|
1325
|
-
3,
|
|
1326
|
-
4
|
|
1327
|
-
]);
|
|
1320
|
+
setIsAuthLoading(true);
|
|
1328
1321
|
return [
|
|
1329
1322
|
4,
|
|
1330
1323
|
dispatch(checkAuthenticated(apiURL))
|
|
1331
1324
|
];
|
|
1332
|
-
case
|
|
1325
|
+
case 1:
|
|
1333
1326
|
_state.sent();
|
|
1334
|
-
|
|
1335
|
-
3,
|
|
1336
|
-
4
|
|
1337
|
-
];
|
|
1338
|
-
case 3:
|
|
1339
|
-
return [
|
|
1340
|
-
7
|
|
1341
|
-
];
|
|
1342
|
-
case 4:
|
|
1327
|
+
setIsAuthLoading(false);
|
|
1343
1328
|
return [
|
|
1344
1329
|
2
|
|
1345
1330
|
];
|
|
@@ -1347,60 +1332,55 @@ var useAuthicatedUser = function(apiURL, location) {
|
|
|
1347
1332
|
});
|
|
1348
1333
|
})();
|
|
1349
1334
|
};
|
|
1350
|
-
|
|
1335
|
+
runAuthCheck();
|
|
1351
1336
|
}, [
|
|
1352
1337
|
dispatch,
|
|
1353
1338
|
apiURL,
|
|
1354
1339
|
location
|
|
1355
1340
|
]);
|
|
1356
1341
|
(0, import_react5.useEffect)(function() {
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
return
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
});
|
|
1380
|
-
})();
|
|
1381
|
-
};
|
|
1382
|
-
if (isAuthenticated !== null) {
|
|
1383
|
-
fetchUserData();
|
|
1342
|
+
if (isAuthenticated) {
|
|
1343
|
+
var loadUserData = function() {
|
|
1344
|
+
return _async_to_generator(function() {
|
|
1345
|
+
return _ts_generator(this, function(_state) {
|
|
1346
|
+
switch(_state.label){
|
|
1347
|
+
case 0:
|
|
1348
|
+
setIsUserLoading(true);
|
|
1349
|
+
return [
|
|
1350
|
+
4,
|
|
1351
|
+
dispatch(load_user(apiURL))
|
|
1352
|
+
];
|
|
1353
|
+
case 1:
|
|
1354
|
+
_state.sent();
|
|
1355
|
+
setIsUserLoading(false);
|
|
1356
|
+
return [
|
|
1357
|
+
2
|
|
1358
|
+
];
|
|
1359
|
+
}
|
|
1360
|
+
});
|
|
1361
|
+
})();
|
|
1362
|
+
};
|
|
1363
|
+
loadUserData();
|
|
1384
1364
|
}
|
|
1385
1365
|
}, [
|
|
1386
1366
|
dispatch,
|
|
1387
|
-
|
|
1388
|
-
|
|
1367
|
+
apiURL,
|
|
1368
|
+
isAuthenticated
|
|
1389
1369
|
]);
|
|
1390
1370
|
var refreshUser = (0, import_react5.useCallback)(function() {
|
|
1391
|
-
setIsLoading(true);
|
|
1392
1371
|
var loadAndFinish = function() {
|
|
1393
1372
|
return _async_to_generator(function() {
|
|
1394
1373
|
return _ts_generator(this, function(_state) {
|
|
1395
1374
|
switch(_state.label){
|
|
1396
1375
|
case 0:
|
|
1376
|
+
setIsUserLoading(true);
|
|
1397
1377
|
return [
|
|
1398
1378
|
4,
|
|
1399
1379
|
dispatch(load_user(apiURL))
|
|
1400
1380
|
];
|
|
1401
1381
|
case 1:
|
|
1402
1382
|
_state.sent();
|
|
1403
|
-
|
|
1383
|
+
setIsUserLoading(false);
|
|
1404
1384
|
return [
|
|
1405
1385
|
2
|
|
1406
1386
|
];
|
|
@@ -1418,37 +1398,14 @@ var useAuthicatedUser = function(apiURL, location) {
|
|
|
1418
1398
|
return _ts_generator(this, function(_state) {
|
|
1419
1399
|
switch(_state.label){
|
|
1420
1400
|
case 0:
|
|
1421
|
-
|
|
1422
|
-
_state.label = 1;
|
|
1423
|
-
case 1:
|
|
1424
|
-
_state.trys.push([
|
|
1425
|
-
1,
|
|
1426
|
-
,
|
|
1427
|
-
4,
|
|
1428
|
-
5
|
|
1429
|
-
]);
|
|
1401
|
+
setIsAuthLoading(true);
|
|
1430
1402
|
return [
|
|
1431
1403
|
4,
|
|
1432
1404
|
dispatch(checkAuthenticated(apiURL))
|
|
1433
1405
|
];
|
|
1434
|
-
case
|
|
1435
|
-
_state.sent();
|
|
1436
|
-
return [
|
|
1437
|
-
4,
|
|
1438
|
-
dispatch(load_user(apiURL))
|
|
1439
|
-
];
|
|
1440
|
-
case 3:
|
|
1406
|
+
case 1:
|
|
1441
1407
|
_state.sent();
|
|
1442
|
-
|
|
1443
|
-
3,
|
|
1444
|
-
5
|
|
1445
|
-
];
|
|
1446
|
-
case 4:
|
|
1447
|
-
setIsLoading(false);
|
|
1448
|
-
return [
|
|
1449
|
-
7
|
|
1450
|
-
];
|
|
1451
|
-
case 5:
|
|
1408
|
+
setIsAuthLoading(false);
|
|
1452
1409
|
return [
|
|
1453
1410
|
2
|
|
1454
1411
|
];
|
|
@@ -1464,6 +1421,7 @@ var useAuthicatedUser = function(apiURL, location) {
|
|
|
1464
1421
|
}, [
|
|
1465
1422
|
dispatch
|
|
1466
1423
|
]);
|
|
1424
|
+
var isLoading = isAuthLoading || isUserLoading;
|
|
1467
1425
|
return {
|
|
1468
1426
|
error: error,
|
|
1469
1427
|
isAuthenticated: isAuthenticated,
|
package/dist/index.mjs
CHANGED
|
@@ -462,53 +462,48 @@ import { useCallback as useCallback5, useEffect as useEffect4, useState as useSt
|
|
|
462
462
|
import { useDispatch as useDispatch5, useSelector as useSelector4 } from "react-redux";
|
|
463
463
|
var useAuthicatedUser = (apiURL, location) => {
|
|
464
464
|
const dispatch = useDispatch5();
|
|
465
|
-
const [
|
|
465
|
+
const [isAuthLoading, setIsAuthLoading] = useState4(true);
|
|
466
|
+
const [isUserLoading, setIsUserLoading] = useState4(false);
|
|
466
467
|
const isAuthenticated = useSelector4(
|
|
467
468
|
(state) => state.auth.isAuthenticated
|
|
468
469
|
);
|
|
469
470
|
const error = useSelector4((state) => state.auth.error);
|
|
470
471
|
const currentUser = useSelector4((state) => state.auth.user);
|
|
471
472
|
useEffect4(() => {
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
} finally {
|
|
477
|
-
}
|
|
473
|
+
const runAuthCheck = async () => {
|
|
474
|
+
setIsAuthLoading(true);
|
|
475
|
+
await dispatch(checkAuthenticated(apiURL));
|
|
476
|
+
setIsAuthLoading(false);
|
|
478
477
|
};
|
|
479
|
-
|
|
478
|
+
runAuthCheck();
|
|
480
479
|
}, [dispatch, apiURL, location]);
|
|
481
480
|
useEffect4(() => {
|
|
482
|
-
|
|
483
|
-
|
|
481
|
+
if (isAuthenticated) {
|
|
482
|
+
const loadUserData = async () => {
|
|
483
|
+
setIsUserLoading(true);
|
|
484
484
|
await dispatch(load_user(apiURL));
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (isAuthenticated !== null) {
|
|
489
|
-
fetchUserData();
|
|
485
|
+
setIsUserLoading(false);
|
|
486
|
+
};
|
|
487
|
+
loadUserData();
|
|
490
488
|
}
|
|
491
|
-
}, [dispatch,
|
|
489
|
+
}, [dispatch, apiURL, isAuthenticated]);
|
|
492
490
|
const refreshUser = useCallback5(() => {
|
|
493
|
-
setIsLoading(true);
|
|
494
491
|
const loadAndFinish = async () => {
|
|
492
|
+
setIsUserLoading(true);
|
|
495
493
|
await dispatch(load_user(apiURL));
|
|
496
|
-
|
|
494
|
+
setIsUserLoading(false);
|
|
497
495
|
};
|
|
498
496
|
loadAndFinish();
|
|
499
497
|
}, [dispatch, apiURL]);
|
|
500
498
|
const refreshAuth = useCallback5(async () => {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
await dispatch(load_user(apiURL));
|
|
505
|
-
} finally {
|
|
506
|
-
setIsLoading(false);
|
|
507
|
-
}
|
|
499
|
+
setIsAuthLoading(true);
|
|
500
|
+
await dispatch(checkAuthenticated(apiURL));
|
|
501
|
+
setIsAuthLoading(false);
|
|
508
502
|
}, [dispatch, apiURL]);
|
|
509
503
|
const clearErrorsWrapper = useCallback5(() => {
|
|
510
504
|
dispatch(clearErrors());
|
|
511
505
|
}, [dispatch]);
|
|
506
|
+
const isLoading = isAuthLoading || isUserLoading;
|
|
512
507
|
return {
|
|
513
508
|
error,
|
|
514
509
|
isAuthenticated,
|