react-redux-django-auth 1.4.0 → 1.4.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/dist/index.d.mts CHANGED
@@ -42,6 +42,7 @@ interface AuthHookReturn {
42
42
  clearErrors: () => void;
43
43
  refreshUser: () => void;
44
44
  refreshAuth: () => Promise<void>;
45
+ isLoading: boolean;
45
46
  }
46
47
  declare const useAuthicatedUser: (apiURL: string, location: any) => AuthHookReturn;
47
48
 
package/dist/index.d.ts CHANGED
@@ -42,6 +42,7 @@ interface AuthHookReturn {
42
42
  clearErrors: () => void;
43
43
  refreshUser: () => void;
44
44
  refreshAuth: () => Promise<void>;
45
+ isLoading: boolean;
45
46
  }
46
47
  declare const useAuthicatedUser: (apiURL: string, location: any) => AuthHookReturn;
47
48
 
package/dist/index.js CHANGED
@@ -1029,6 +1029,7 @@ var useActivate = function(uid, token, apiUrl) {
1029
1029
  });
1030
1030
  var isStatus204 = status === 204;
1031
1031
  (0, import_react.useEffect)(function() {
1032
+ dispatch(clearErrors());
1032
1033
  return function() {
1033
1034
  dispatch(clearErrors());
1034
1035
  };
@@ -1116,6 +1117,7 @@ var useLogin = function(initialFields, apiUrl) {
1116
1117
  });
1117
1118
  var isStatus200 = status === 200;
1118
1119
  (0, import_react2.useEffect)(function() {
1120
+ dispatch(clearErrors());
1119
1121
  return function() {
1120
1122
  dispatch(clearErrors());
1121
1123
  };
@@ -1221,6 +1223,7 @@ var useSignup = function(initialFields, apiUrl) {
1221
1223
  });
1222
1224
  var isStatus201 = status === 201;
1223
1225
  (0, import_react4.useEffect)(function() {
1226
+ dispatch(clearErrors());
1224
1227
  return function() {
1225
1228
  dispatch(clearErrors());
1226
1229
  };
@@ -1300,6 +1303,8 @@ var import_react5 = require("react");
1300
1303
  var import_react_redux5 = require("react-redux");
1301
1304
  var useAuthicatedUser = function(apiURL, location) {
1302
1305
  var dispatch = (0, import_react_redux5.useDispatch)();
1306
+ var _ref = _sliced_to_array((0, import_react5.useState)(true), 2), isAuthLoading = _ref[0], setIsAuthLoading = _ref[1];
1307
+ var _ref1 = _sliced_to_array((0, import_react5.useState)(false), 2), isUserLoading = _ref1[0], setIsUserLoading = _ref1[1];
1303
1308
  var isAuthenticated = (0, import_react_redux5.useSelector)(function(state) {
1304
1309
  return state.auth.isAuthenticated;
1305
1310
  });
@@ -1310,7 +1315,27 @@ var useAuthicatedUser = function(apiURL, location) {
1310
1315
  return state.auth.user;
1311
1316
  });
1312
1317
  (0, import_react5.useEffect)(function() {
1313
- dispatch(checkAuthenticated(apiURL));
1318
+ var runAuthCheck = function() {
1319
+ return _async_to_generator(function() {
1320
+ return _ts_generator(this, function(_state) {
1321
+ switch(_state.label){
1322
+ case 0:
1323
+ setIsAuthLoading(true);
1324
+ return [
1325
+ 4,
1326
+ dispatch(checkAuthenticated(apiURL))
1327
+ ];
1328
+ case 1:
1329
+ _state.sent();
1330
+ setIsAuthLoading(false);
1331
+ return [
1332
+ 2
1333
+ ];
1334
+ }
1335
+ });
1336
+ })();
1337
+ };
1338
+ runAuthCheck();
1314
1339
  }, [
1315
1340
  dispatch,
1316
1341
  apiURL,
@@ -1318,7 +1343,27 @@ var useAuthicatedUser = function(apiURL, location) {
1318
1343
  ]);
1319
1344
  (0, import_react5.useEffect)(function() {
1320
1345
  if (isAuthenticated) {
1321
- dispatch(load_user(apiURL));
1346
+ var runUserLoad = function() {
1347
+ return _async_to_generator(function() {
1348
+ return _ts_generator(this, function(_state) {
1349
+ switch(_state.label){
1350
+ case 0:
1351
+ setIsUserLoading(true);
1352
+ return [
1353
+ 4,
1354
+ dispatch(load_user(apiURL))
1355
+ ];
1356
+ case 1:
1357
+ _state.sent();
1358
+ setIsUserLoading(false);
1359
+ return [
1360
+ 2
1361
+ ];
1362
+ }
1363
+ });
1364
+ })();
1365
+ };
1366
+ runUserLoad();
1322
1367
  }
1323
1368
  }, [
1324
1369
  dispatch,
@@ -1358,13 +1403,15 @@ var useAuthicatedUser = function(apiURL, location) {
1358
1403
  }, [
1359
1404
  dispatch
1360
1405
  ]);
1406
+ var isLoading = isAuthLoading || isUserLoading;
1361
1407
  return {
1362
1408
  error: error,
1363
1409
  isAuthenticated: isAuthenticated,
1364
1410
  currentUser: currentUser,
1365
1411
  clearErrors: clearErrorsWrapper,
1366
1412
  refreshUser: refreshUser,
1367
- refreshAuth: refreshAuth
1413
+ refreshAuth: refreshAuth,
1414
+ isLoading: isLoading
1368
1415
  };
1369
1416
  };
1370
1417
  var useLoadUser_default = useAuthicatedUser;
@@ -1383,6 +1430,7 @@ var useResetPassword = function(apiUrl) {
1383
1430
  });
1384
1431
  var isStatus204 = status === 204;
1385
1432
  (0, import_react6.useEffect)(function() {
1433
+ dispatch(clearErrors());
1386
1434
  return function() {
1387
1435
  dispatch(clearErrors());
1388
1436
  };
@@ -1468,6 +1516,7 @@ var usePasswordConfirm = function(initialFields, apiUrl) {
1468
1516
  });
1469
1517
  var isStatus204 = status === 204;
1470
1518
  (0, import_react7.useEffect)(function() {
1519
+ dispatch(clearErrors());
1471
1520
  return function() {
1472
1521
  dispatch(clearErrors());
1473
1522
  };
@@ -1556,6 +1605,7 @@ var useChangeAuthenticatedUserPassword = function(initialFields, apiUrl) {
1556
1605
  return state.auth.status;
1557
1606
  });
1558
1607
  (0, import_react8.useEffect)(function() {
1608
+ dispatch(clearErrors());
1559
1609
  return function() {
1560
1610
  dispatch(clearErrors());
1561
1611
  };
@@ -1751,6 +1801,7 @@ var useGoogleAuth = function(apiUrl) {
1751
1801
  dispatch
1752
1802
  ]);
1753
1803
  (0, import_react9.useEffect)(function() {
1804
+ dispatch(clearErrors());
1754
1805
  return function() {
1755
1806
  dispatch(clearErrors());
1756
1807
  };
@@ -1885,6 +1936,7 @@ var useFacebookAuth = function(apiUrl) {
1885
1936
  dispatch
1886
1937
  ]);
1887
1938
  (0, import_react10.useEffect)(function() {
1939
+ dispatch(clearErrors());
1888
1940
  return function() {
1889
1941
  dispatch(clearErrors());
1890
1942
  };
package/dist/index.mjs CHANGED
@@ -318,6 +318,7 @@ var useActivate = (uid, token, apiUrl) => {
318
318
  const status = useSelector((state) => state.auth.status);
319
319
  const isStatus204 = status === 204;
320
320
  useEffect(() => {
321
+ dispatch(clearErrors());
321
322
  return () => {
322
323
  dispatch(clearErrors());
323
324
  };
@@ -361,6 +362,7 @@ var useLogin = (initialFields, apiUrl) => {
361
362
  const currentUser = useSelector2((state) => state.auth.user);
362
363
  const isStatus200 = status === 200;
363
364
  useEffect2(() => {
365
+ dispatch(clearErrors());
364
366
  return () => {
365
367
  dispatch(clearErrors());
366
368
  };
@@ -422,6 +424,7 @@ var useSignup = (initialFields, apiUrl) => {
422
424
  const status = useSelector3((state) => state.auth.status);
423
425
  const isStatus201 = status === 201;
424
426
  useEffect3(() => {
427
+ dispatch(clearErrors());
425
428
  return () => {
426
429
  dispatch(clearErrors());
427
430
  };
@@ -458,21 +461,33 @@ var useSignup = (initialFields, apiUrl) => {
458
461
  var useSignup_default = useSignup;
459
462
 
460
463
  // src/hooks/useLoadUser.tsx
461
- import { useCallback as useCallback5, useEffect as useEffect4 } from "react";
464
+ import { useCallback as useCallback5, useEffect as useEffect4, useState as useState4 } from "react";
462
465
  import { useDispatch as useDispatch5, useSelector as useSelector4 } from "react-redux";
463
466
  var useAuthicatedUser = (apiURL, location) => {
464
467
  const dispatch = useDispatch5();
468
+ const [isAuthLoading, setIsAuthLoading] = useState4(true);
469
+ const [isUserLoading, setIsUserLoading] = useState4(false);
465
470
  const isAuthenticated = useSelector4(
466
471
  (state) => state.auth.isAuthenticated
467
472
  );
468
473
  const error = useSelector4((state) => state.auth.error);
469
474
  const currentUser = useSelector4((state) => state.auth.user);
470
475
  useEffect4(() => {
471
- dispatch(checkAuthenticated(apiURL));
476
+ const runAuthCheck = async () => {
477
+ setIsAuthLoading(true);
478
+ await dispatch(checkAuthenticated(apiURL));
479
+ setIsAuthLoading(false);
480
+ };
481
+ runAuthCheck();
472
482
  }, [dispatch, apiURL, location]);
473
483
  useEffect4(() => {
474
484
  if (isAuthenticated) {
475
- dispatch(load_user(apiURL));
485
+ const runUserLoad = async () => {
486
+ setIsUserLoading(true);
487
+ await dispatch(load_user(apiURL));
488
+ setIsUserLoading(false);
489
+ };
490
+ runUserLoad();
476
491
  }
477
492
  }, [dispatch, isAuthenticated, apiURL]);
478
493
  const refreshUser = useCallback5(() => {
@@ -485,28 +500,31 @@ var useAuthicatedUser = (apiURL, location) => {
485
500
  const clearErrorsWrapper = useCallback5(() => {
486
501
  dispatch(clearErrors());
487
502
  }, [dispatch]);
503
+ const isLoading = isAuthLoading || isUserLoading;
488
504
  return {
489
505
  error,
490
506
  isAuthenticated,
491
507
  currentUser,
492
508
  clearErrors: clearErrorsWrapper,
493
509
  refreshUser,
494
- refreshAuth
510
+ refreshAuth,
511
+ isLoading
495
512
  };
496
513
  };
497
514
  var useLoadUser_default = useAuthicatedUser;
498
515
 
499
516
  // src/hooks/useResetPassword.tsx
500
- import { useState as useState4, useCallback as useCallback6, useEffect as useEffect5 } from "react";
517
+ import { useState as useState5, useCallback as useCallback6, useEffect as useEffect5 } from "react";
501
518
  import { useDispatch as useDispatch6, useSelector as useSelector5 } from "react-redux";
502
519
  var useResetPassword = (apiUrl) => {
503
520
  const dispatch = useDispatch6();
504
- const [loading, setLoading] = useState4(false);
505
- const [email, setEmail] = useState4("");
521
+ const [loading, setLoading] = useState5(false);
522
+ const [email, setEmail] = useState5("");
506
523
  const status = useSelector5((state) => state.auth.status);
507
524
  const error = useSelector5((state) => state.auth.error);
508
525
  const isStatus204 = status === 204;
509
526
  useEffect5(() => {
527
+ dispatch(clearErrors());
510
528
  return () => {
511
529
  dispatch(clearErrors());
512
530
  };
@@ -541,16 +559,17 @@ var useResetPassword = (apiUrl) => {
541
559
  var useResetPassword_default = useResetPassword;
542
560
 
543
561
  // src/hooks/usePasswordConfirm.tsx
544
- import { useState as useState5, useCallback as useCallback7, useEffect as useEffect6 } from "react";
562
+ import { useState as useState6, useCallback as useCallback7, useEffect as useEffect6 } from "react";
545
563
  import { useDispatch as useDispatch7, useSelector as useSelector6 } from "react-redux";
546
564
  var usePasswordConfirm = (initialFields, apiUrl) => {
547
565
  const dispatch = useDispatch7();
548
- const [loading, setLoading] = useState5(false);
549
- const [formData, setFormData] = useState5(initialFields);
566
+ const [loading, setLoading] = useState6(false);
567
+ const [formData, setFormData] = useState6(initialFields);
550
568
  const error = useSelector6((state) => state.auth.error);
551
569
  const status = useSelector6((state) => state.auth.status);
552
570
  const isStatus204 = status === 204;
553
571
  useEffect6(() => {
572
+ dispatch(clearErrors());
554
573
  return () => {
555
574
  dispatch(clearErrors());
556
575
  };
@@ -586,16 +605,17 @@ var usePasswordConfirm = (initialFields, apiUrl) => {
586
605
  var usePasswordConfirm_default = usePasswordConfirm;
587
606
 
588
607
  // src/hooks/useChangePassword.tsx
589
- import { useState as useState6, useCallback as useCallback8, useEffect as useEffect7 } from "react";
608
+ import { useState as useState7, useCallback as useCallback8, useEffect as useEffect7 } from "react";
590
609
  import { useDispatch as useDispatch8, useSelector as useSelector7 } from "react-redux";
591
610
  var useChangeAuthenticatedUserPassword = (initialFields, apiUrl) => {
592
611
  const dispatch = useDispatch8();
593
- const [loading, setLoading] = useState6(false);
594
- const [formData, setFormData] = useState6(initialFields);
595
- const [error, setError] = useState6(null);
612
+ const [loading, setLoading] = useState7(false);
613
+ const [formData, setFormData] = useState7(initialFields);
614
+ const [error, setError] = useState7(null);
596
615
  const authError = useSelector7((state) => state.auth.error);
597
616
  const status = useSelector7((state) => state.auth.status);
598
617
  useEffect7(() => {
618
+ dispatch(clearErrors());
599
619
  return () => {
600
620
  dispatch(clearErrors());
601
621
  };
@@ -637,7 +657,7 @@ var useChangePassword_default = useChangeAuthenticatedUserPassword;
637
657
 
638
658
  // src/hooks/useGoogleAuth.tsx
639
659
  import { useDispatch as useDispatch9, useSelector as useSelector8 } from "react-redux";
640
- import { useEffect as useEffect8, useCallback as useCallback9, useState as useState7 } from "react";
660
+ import { useEffect as useEffect8, useCallback as useCallback9, useState as useState8 } from "react";
641
661
  import axios2 from "axios";
642
662
  var useGoogleAuth = (apiUrl) => {
643
663
  const dispatch = useDispatch9();
@@ -646,7 +666,7 @@ var useGoogleAuth = (apiUrl) => {
646
666
  );
647
667
  const error = useSelector8((state) => state.auth.error);
648
668
  const status = useSelector8((state) => state.auth.status);
649
- const [loading, setLoading] = useState7(false);
669
+ const [loading, setLoading] = useState8(false);
650
670
  const isStatus201 = status === 201;
651
671
  const continueWithGoogle = useCallback9(async () => {
652
672
  setLoading(true);
@@ -678,6 +698,7 @@ var useGoogleAuth = (apiUrl) => {
678
698
  [apiUrl, dispatch]
679
699
  );
680
700
  useEffect8(() => {
701
+ dispatch(clearErrors());
681
702
  return () => {
682
703
  dispatch(clearErrors());
683
704
  };
@@ -695,7 +716,7 @@ var useGoogleAuth_default = useGoogleAuth;
695
716
 
696
717
  // src/hooks/useFacebookAuth.tsx
697
718
  import { useDispatch as useDispatch10, useSelector as useSelector9 } from "react-redux";
698
- import { useEffect as useEffect9, useCallback as useCallback10, useState as useState8 } from "react";
719
+ import { useEffect as useEffect9, useCallback as useCallback10, useState as useState9 } from "react";
699
720
  import axios3 from "axios";
700
721
  var useFacebookAuth = (apiUrl) => {
701
722
  const dispatch = useDispatch10();
@@ -704,7 +725,7 @@ var useFacebookAuth = (apiUrl) => {
704
725
  );
705
726
  const error = useSelector9((state) => state.auth.error);
706
727
  const status = useSelector9((state) => state.auth.status);
707
- const [loading, setLoading] = useState8(false);
728
+ const [loading, setLoading] = useState9(false);
708
729
  const isStatus201 = status === 201;
709
730
  const continueWithFacebook = useCallback10(async () => {
710
731
  setLoading(true);
@@ -736,6 +757,7 @@ var useFacebookAuth = (apiUrl) => {
736
757
  [apiUrl, dispatch]
737
758
  );
738
759
  useEffect9(() => {
760
+ dispatch(clearErrors());
739
761
  return () => {
740
762
  dispatch(clearErrors());
741
763
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-redux-django-auth",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "A React Redux Authentication system for django app built with TypeScript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",