react-redux-django-auth 1.4.4 → 1.4.6

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.
Files changed (68) hide show
  1. package/README.md +77 -0
  2. package/dist/auth-core/actions/authActions.d.ts +57 -0
  3. package/dist/auth-core/actions/authActions.js +451 -0
  4. package/dist/auth-core/actions/types.d.ts +26 -0
  5. package/dist/auth-core/actions/types.js +22 -0
  6. package/dist/auth-core/apis/apis.d.ts +1 -0
  7. package/dist/auth-core/apis/apis.js +11 -0
  8. package/dist/auth-core/apis/config.d.ts +2 -0
  9. package/dist/auth-core/apis/config.js +10 -0
  10. package/dist/auth-core/hooks/useActivate.d.ts +9 -0
  11. package/dist/auth-core/hooks/useActivate.js +96 -0
  12. package/dist/auth-core/hooks/useChangePassword.d.ts +16 -0
  13. package/dist/auth-core/hooks/useChangePassword.js +121 -0
  14. package/dist/auth-core/hooks/useFacebookAuth.d.ts +11 -0
  15. package/dist/auth-core/hooks/useFacebookAuth.js +125 -0
  16. package/dist/auth-core/hooks/useGoogleAuth.d.ts +11 -0
  17. package/dist/auth-core/hooks/useGoogleAuth.js +125 -0
  18. package/dist/auth-core/hooks/useLoadUser.d.ts +12 -0
  19. package/dist/auth-core/hooks/useLoadUser.js +116 -0
  20. package/dist/auth-core/hooks/useLogin.d.ts +13 -0
  21. package/dist/auth-core/hooks/useLogin.js +119 -0
  22. package/dist/auth-core/hooks/useLogout.d.ts +3 -0
  23. package/dist/auth-core/hooks/useLogout.js +14 -0
  24. package/dist/auth-core/hooks/usePasswordConfirm.d.ts +17 -0
  25. package/dist/auth-core/hooks/usePasswordConfirm.js +117 -0
  26. package/dist/auth-core/hooks/useResetPassword.d.ts +11 -0
  27. package/dist/auth-core/hooks/useResetPassword.js +102 -0
  28. package/dist/auth-core/hooks/useSignup.d.ts +12 -0
  29. package/dist/auth-core/hooks/useSignup.js +115 -0
  30. package/dist/auth-core/reducers/authReducer.d.ts +10 -0
  31. package/dist/auth-core/reducers/authReducer.js +58 -0
  32. package/dist/auth-core/reducers/index.d.ts +7 -0
  33. package/dist/auth-core/reducers/index.js +6 -0
  34. package/dist/auth-core/setup/setupAuth.d.ts +4 -0
  35. package/dist/auth-core/setup/setupAuth.js +137 -0
  36. package/dist/auth-core/utils/ExtractErrorMsg.d.ts +33 -0
  37. package/dist/auth-core/utils/ExtractErrorMsg.js +38 -0
  38. package/dist/auth-native/AuthProvider.d.ts +7 -0
  39. package/dist/auth-native/AuthProvider.js +14 -0
  40. package/dist/auth-native/biometrics/biometricService.d.ts +4 -0
  41. package/dist/auth-native/biometrics/biometricService.js +74 -0
  42. package/dist/auth-native/hooks/useBiometricAuth.d.ts +9 -0
  43. package/dist/auth-native/hooks/useBiometricAuth.js +87 -0
  44. package/dist/auth-native/hooks/useGoogleAuth.d.ts +13 -0
  45. package/dist/auth-native/hooks/useGoogleAuth.js +145 -0
  46. package/dist/auth-native/index.d.ts +6 -0
  47. package/dist/auth-native/index.js +6 -0
  48. package/dist/auth-native/storage/nativeStorage.d.ts +18 -0
  49. package/dist/auth-native/storage/nativeStorage.js +111 -0
  50. package/dist/auth-native/store.d.ts +8 -0
  51. package/dist/auth-native/store.js +9 -0
  52. package/dist/auth-web/authProvider.d.ts +7 -0
  53. package/dist/auth-web/authProvider.js +14 -0
  54. package/dist/auth-web/hooks/useGoogleAuth.d.ts +11 -0
  55. package/dist/auth-web/hooks/useGoogleAuth.js +126 -0
  56. package/dist/auth-web/index.d.ts +6 -0
  57. package/dist/auth-web/index.js +6 -0
  58. package/dist/auth-web/oauth/google.d.ts +3 -0
  59. package/dist/auth-web/oauth/google.js +93 -0
  60. package/dist/auth-web/storage/webStorage.d.ts +5 -0
  61. package/dist/auth-web/storage/webStorage.js +13 -0
  62. package/dist/auth-web/store.d.ts +8 -0
  63. package/dist/auth-web/store.js +9 -0
  64. package/dist/index.d.mts +21 -140
  65. package/dist/index.d.ts +12 -150
  66. package/dist/index.js +12 -2107
  67. package/dist/index.mjs +72 -839
  68. package/package.json +42 -7
@@ -0,0 +1,119 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { useState, useCallback, useEffect } from "react";
49
+ import { useDispatch, useSelector } from "react-redux";
50
+ import { login, clearErrors } from "../actions/authActions";
51
+ // The custom hook is now typed with its parameters and return value
52
+ var useLogin = function (initialFields, location, storage) {
53
+ var _a = useState(false), loading = _a[0], setLoading = _a[1];
54
+ var _b = useState(initialFields), formData = _b[0], setFormData = _b[1];
55
+ // useDispatch is typed with our custom AppDispatch
56
+ var dispatch = useDispatch();
57
+ // useSelector is typed with RootState for type-safe state access
58
+ var isAuthenticated = useSelector(function (state) { return state.auth.isAuthenticated; });
59
+ var error = useSelector(function (state) { return state.auth.error; });
60
+ var status = useSelector(function (state) { return state.auth.status; });
61
+ var currentUser = useSelector(function (state) { return state.auth.user; });
62
+ // The type for status is inferred, making this comparison type-safe
63
+ var isStatus200 = status === 200;
64
+ useEffect(function () {
65
+ // Clear errors when the component mounts
66
+ dispatch(clearErrors());
67
+ // Clear errors when the component unmounts
68
+ return function () {
69
+ dispatch(clearErrors());
70
+ };
71
+ }, [dispatch, location]); // Dependency array includes dispatch
72
+ // useCallback is typed to ensure the event handler has the correct signature
73
+ var handleChange = useCallback(function (e) {
74
+ var _a = e.target, name = _a.name, value = _a.value;
75
+ setFormData(function (prevFields) {
76
+ var _a;
77
+ return (__assign(__assign({}, prevFields), (_a = {}, _a[name] = value, _a)));
78
+ });
79
+ }, []);
80
+ var handleSubmit = useCallback(function (e) { return __awaiter(void 0, void 0, void 0, function () {
81
+ var error_1;
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0:
85
+ e.preventDefault();
86
+ setLoading(true);
87
+ _a.label = 1;
88
+ case 1:
89
+ _a.trys.push([1, 3, 4, 5]);
90
+ // The dispatch call is type-safe
91
+ return [4 /*yield*/, dispatch(login(formData, storage))];
92
+ case 2:
93
+ // The dispatch call is type-safe
94
+ _a.sent();
95
+ return [3 /*break*/, 5];
96
+ case 3:
97
+ error_1 = _a.sent();
98
+ // handle login error
99
+ console.error("Error submitting form", error_1);
100
+ return [3 /*break*/, 5];
101
+ case 4:
102
+ setLoading(false);
103
+ return [7 /*endfinally*/];
104
+ case 5: return [2 /*return*/];
105
+ }
106
+ });
107
+ }); }, [dispatch, formData, storage]);
108
+ return {
109
+ loading: loading,
110
+ formData: formData,
111
+ error: error,
112
+ onChange: handleChange,
113
+ onSubmit: handleSubmit,
114
+ isAuthenticated: isAuthenticated,
115
+ isStatus200: isStatus200,
116
+ currentUser: currentUser,
117
+ };
118
+ };
119
+ export default useLogin;
@@ -0,0 +1,3 @@
1
+ import { AuthStorage } from "../actions/types";
2
+ declare const useLogout: (storage: AuthStorage) => (() => void);
3
+ export default useLogout;
@@ -0,0 +1,14 @@
1
+ import { useCallback } from "react";
2
+ import { useDispatch } from "react-redux";
3
+ import { logout } from "../actions/authActions";
4
+ // The custom hook is now typed with its return value
5
+ var useLogout = function (storage) {
6
+ // useDispatch is typed with our custom AppDispatch
7
+ var dispatch = useDispatch();
8
+ // The handleLogout function is memoized and typed
9
+ var handleLogout = useCallback(function () {
10
+ dispatch(logout(storage));
11
+ }, [dispatch]);
12
+ return handleLogout;
13
+ };
14
+ export default useLogout;
@@ -0,0 +1,17 @@
1
+ interface FormData {
2
+ new_password?: string;
3
+ re_new_password?: string;
4
+ uid?: string;
5
+ token?: string;
6
+ }
7
+ interface PasswordConfirmHookReturn {
8
+ loading: boolean;
9
+ formData: FormData;
10
+ error: any;
11
+ onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
12
+ onSubmit: (e: React.FormEvent) => Promise<void>;
13
+ status: any;
14
+ isStatus204: boolean;
15
+ }
16
+ declare const usePasswordConfirm: (initialFields: FormData) => PasswordConfirmHookReturn;
17
+ export default usePasswordConfirm;
@@ -0,0 +1,117 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { useState, useCallback, useEffect } from "react";
49
+ import { useDispatch, useSelector } from "react-redux";
50
+ import { reset_password_confirm, clearErrors } from "../actions/authActions";
51
+ // The custom hook is now typed with its parameters and return value
52
+ var usePasswordConfirm = function (initialFields) {
53
+ // useDispatch is typed with our custom AppDispatch
54
+ var dispatch = useDispatch();
55
+ // useState is typed as boolean and FormData
56
+ var _a = useState(false), loading = _a[0], setLoading = _a[1];
57
+ var _b = useState(initialFields), formData = _b[0], setFormData = _b[1];
58
+ // useSelector is typed with AuthState for type-safe state access
59
+ var error = useSelector(function (state) { return state.auth.error; });
60
+ var status = useSelector(function (state) { return state.auth.status; });
61
+ var isStatus204 = status === 204;
62
+ useEffect(function () {
63
+ // Clear errors when the component mounts
64
+ dispatch(clearErrors());
65
+ // Clear errors when the component unmounts
66
+ return function () {
67
+ dispatch(clearErrors());
68
+ };
69
+ }, [dispatch]);
70
+ // useCallback is typed to ensure the event handler has the correct signature
71
+ var handleChange = useCallback(function (e) {
72
+ var _a = e.target, name = _a.name, value = _a.value;
73
+ setFormData(function (prevFields) {
74
+ var _a;
75
+ return (__assign(__assign({}, prevFields), (_a = {}, _a[name] = value, _a)));
76
+ });
77
+ }, []);
78
+ // useCallback is typed to ensure the event handler has the correct signature
79
+ var handleSubmit = useCallback(function (e) { return __awaiter(void 0, void 0, void 0, function () {
80
+ var err_1;
81
+ return __generator(this, function (_a) {
82
+ switch (_a.label) {
83
+ case 0:
84
+ e.preventDefault();
85
+ setLoading(true);
86
+ _a.label = 1;
87
+ case 1:
88
+ _a.trys.push([1, 3, 4, 5]);
89
+ // The dispatch call is type-safe
90
+ return [4 /*yield*/, dispatch(reset_password_confirm(formData))];
91
+ case 2:
92
+ // The dispatch call is type-safe
93
+ _a.sent();
94
+ return [3 /*break*/, 5];
95
+ case 3:
96
+ err_1 = _a.sent();
97
+ // You can handle login error here if needed
98
+ console.error("Error submitting form", err_1);
99
+ return [3 /*break*/, 5];
100
+ case 4:
101
+ setLoading(false);
102
+ return [7 /*endfinally*/];
103
+ case 5: return [2 /*return*/];
104
+ }
105
+ });
106
+ }); }, [dispatch, formData]);
107
+ return {
108
+ loading: loading,
109
+ formData: formData,
110
+ error: error,
111
+ onChange: handleChange,
112
+ onSubmit: handleSubmit,
113
+ status: status,
114
+ isStatus204: isStatus204,
115
+ };
116
+ };
117
+ export default usePasswordConfirm;
@@ -0,0 +1,11 @@
1
+ interface ResetPasswordHookReturn {
2
+ email: string;
3
+ loading: boolean;
4
+ handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
5
+ status: any;
6
+ error: any;
7
+ handleSubmit: (e: React.FormEvent) => Promise<void>;
8
+ isStatus204: boolean;
9
+ }
10
+ declare const useResetPassword: () => ResetPasswordHookReturn;
11
+ export default useResetPassword;
@@ -0,0 +1,102 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { useState, useCallback, useEffect } from "react";
38
+ import { useDispatch, useSelector } from "react-redux";
39
+ import { reset_password, clearErrors } from "../actions/authActions";
40
+ // The custom hook is now typed with its parameters and return value
41
+ var useResetPassword = function () {
42
+ // useDispatch is typed with our custom AppDispatch
43
+ var dispatch = useDispatch();
44
+ // useState is typed as boolean and string
45
+ var _a = useState(false), loading = _a[0], setLoading = _a[1];
46
+ var _b = useState(""), email = _b[0], setEmail = _b[1];
47
+ // useSelector is typed with AuthState for type-safe state access
48
+ var status = useSelector(function (state) { return state.auth.status; });
49
+ var error = useSelector(function (state) { return state.auth.error; });
50
+ var isStatus204 = status === 204;
51
+ useEffect(function () {
52
+ // Clear errors when the component mounts
53
+ dispatch(clearErrors());
54
+ // Clear errors when the component unmounts
55
+ return function () {
56
+ dispatch(clearErrors());
57
+ };
58
+ }, [dispatch]);
59
+ // useCallback is typed to ensure the event handler has the correct signature
60
+ var handleChange = useCallback(function (e) {
61
+ setEmail(e.target.value);
62
+ }, []);
63
+ // useCallback is typed to ensure the event handler has the correct signature
64
+ var handleSubmit = useCallback(function (e) { return __awaiter(void 0, void 0, void 0, function () {
65
+ var err_1;
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0:
69
+ e.preventDefault();
70
+ setLoading(true);
71
+ _a.label = 1;
72
+ case 1:
73
+ _a.trys.push([1, 3, 4, 5]);
74
+ // The dispatch call is type-safe
75
+ return [4 /*yield*/, dispatch(reset_password(email))];
76
+ case 2:
77
+ // The dispatch call is type-safe
78
+ _a.sent();
79
+ return [3 /*break*/, 5];
80
+ case 3:
81
+ err_1 = _a.sent();
82
+ // You can handle error here if needed
83
+ console.error("Error submitting form", err_1);
84
+ return [3 /*break*/, 5];
85
+ case 4:
86
+ setLoading(false);
87
+ return [7 /*endfinally*/];
88
+ case 5: return [2 /*return*/];
89
+ }
90
+ });
91
+ }); }, [dispatch, email]);
92
+ return {
93
+ email: email,
94
+ loading: loading,
95
+ handleChange: handleChange,
96
+ status: status,
97
+ error: error,
98
+ handleSubmit: handleSubmit,
99
+ isStatus204: isStatus204,
100
+ };
101
+ };
102
+ export default useResetPassword;
@@ -0,0 +1,12 @@
1
+ interface SignupHookReturn {
2
+ loading: boolean;
3
+ formData: any;
4
+ error: any;
5
+ onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
6
+ onSubmit: (e: React.FormEvent) => Promise<void>;
7
+ isAuthenticated: boolean | null;
8
+ status: any;
9
+ isStatus201: boolean;
10
+ }
11
+ declare const useSignup: (initialFields: any, location: any) => SignupHookReturn;
12
+ export default useSignup;
@@ -0,0 +1,115 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { useState, useCallback, useEffect } from "react";
49
+ import { useDispatch, useSelector } from "react-redux";
50
+ import { signup, clearErrors } from "../actions/authActions";
51
+ // The custom hook is now typed with its parameters and return value
52
+ var useSignup = function (initialFields, location) {
53
+ var _a = useState(false), loading = _a[0], setLoading = _a[1];
54
+ var _b = useState(initialFields), formData = _b[0], setFormData = _b[1];
55
+ // useDispatch is typed with our custom AppDispatch
56
+ var dispatch = useDispatch();
57
+ // useSelector is typed with RootState for type-safe state access
58
+ var isAuthenticated = useSelector(function (state) { return state.auth.isAuthenticated; });
59
+ var error = useSelector(function (state) { return state.auth.error; });
60
+ var status = useSelector(function (state) { return state.auth.status; });
61
+ var isStatus201 = status === 201;
62
+ useEffect(function () {
63
+ // Clear errors when the component mounts
64
+ console.log("Clearing errors on mount...");
65
+ dispatch(clearErrors());
66
+ // Clear errors when the component unmounts
67
+ return function () {
68
+ console.log("Clearing errors on unmount...");
69
+ dispatch(clearErrors());
70
+ };
71
+ }, [dispatch, location]);
72
+ var handleChange = useCallback(function (e) {
73
+ var _a = e.target, name = _a.name, value = _a.value;
74
+ setFormData(function (prevFields) {
75
+ var _a;
76
+ return (__assign(__assign({}, prevFields), (_a = {}, _a[name] = value, _a)));
77
+ });
78
+ }, []);
79
+ var handleSubmit = useCallback(function (e) { return __awaiter(void 0, void 0, void 0, function () {
80
+ var error_1;
81
+ return __generator(this, function (_a) {
82
+ switch (_a.label) {
83
+ case 0:
84
+ e.preventDefault();
85
+ setLoading(true);
86
+ _a.label = 1;
87
+ case 1:
88
+ _a.trys.push([1, 3, 4, 5]);
89
+ return [4 /*yield*/, dispatch(signup(formData))];
90
+ case 2:
91
+ _a.sent();
92
+ return [3 /*break*/, 5];
93
+ case 3:
94
+ error_1 = _a.sent();
95
+ console.error("Error submitting form", error_1);
96
+ return [3 /*break*/, 5];
97
+ case 4:
98
+ setLoading(false);
99
+ return [7 /*endfinally*/];
100
+ case 5: return [2 /*return*/];
101
+ }
102
+ });
103
+ }); }, [dispatch, formData]);
104
+ return {
105
+ loading: loading,
106
+ formData: formData,
107
+ error: error,
108
+ onChange: handleChange,
109
+ onSubmit: handleSubmit,
110
+ isAuthenticated: isAuthenticated,
111
+ status: status,
112
+ isStatus201: isStatus201,
113
+ };
114
+ };
115
+ export default useSignup;
@@ -0,0 +1,10 @@
1
+ export interface AuthState {
2
+ access: string | null;
3
+ refresh: string | null;
4
+ isAuthenticated: boolean | null;
5
+ user: any;
6
+ error: any;
7
+ status: any;
8
+ }
9
+ export declare const initialState: AuthState;
10
+ export default function authReducer(state: AuthState | undefined, action: any): AuthState;
@@ -0,0 +1,58 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { LOGIN_SUCCESS, LOGIN_FAIL, USER_LOADED_SUCCESS, USER_LOADED_FAIL, AUTHENTICATED_SUCCESS, AUTHENTICATED_FAIL, PASSWORD_RESET_SUCCESS, PASSWORD_RESET_FAIL, PASSWORD_RESET_CONFIRM_SUCCESS, PASSWORD_RESET_CONFIRM_FAIL, SIGNUP_SUCCESS, SIGNUP_FAIL, ACTIVATION_SUCCESS, ACTIVATION_FAIL, GOOGLE_AUTH_SUCCESS, GOOGLE_AUTH_FAIL, FACEBOOK_AUTH_SUCCESS, FACEBOOK_AUTH_FAIL, LOGOUT, CLEAR_ERRORS } from '../actions/types';
13
+ export var initialState = {
14
+ access: null,
15
+ refresh: null,
16
+ isAuthenticated: null,
17
+ user: null,
18
+ error: null,
19
+ status: null,
20
+ };
21
+ export default function authReducer(state, action) {
22
+ if (state === void 0) { state = initialState; }
23
+ var type = action.type, payload = action.payload;
24
+ switch (type) {
25
+ case AUTHENTICATED_SUCCESS:
26
+ return __assign(__assign({}, state), { isAuthenticated: true });
27
+ case LOGIN_SUCCESS:
28
+ case GOOGLE_AUTH_SUCCESS:
29
+ case FACEBOOK_AUTH_SUCCESS:
30
+ return __assign(__assign({}, state), { isAuthenticated: true, access: payload.access, refresh: payload.refresh, status: payload.status });
31
+ case SIGNUP_SUCCESS:
32
+ return __assign(__assign({}, state), { isAuthenticated: false, status: payload });
33
+ case USER_LOADED_SUCCESS:
34
+ return __assign(__assign({}, state), { user: payload });
35
+ case AUTHENTICATED_FAIL:
36
+ return __assign(__assign({}, state), { isAuthenticated: false });
37
+ case USER_LOADED_FAIL:
38
+ return __assign(__assign({}, state), { user: null });
39
+ case GOOGLE_AUTH_FAIL:
40
+ case FACEBOOK_AUTH_FAIL:
41
+ case LOGIN_FAIL:
42
+ case SIGNUP_FAIL:
43
+ case LOGOUT:
44
+ return __assign(__assign({}, state), { access: null, refresh: null, isAuthenticated: false, user: null, error: payload });
45
+ case PASSWORD_RESET_SUCCESS:
46
+ case PASSWORD_RESET_CONFIRM_SUCCESS:
47
+ case ACTIVATION_SUCCESS:
48
+ return __assign(__assign({}, state), { status: payload });
49
+ case ACTIVATION_FAIL:
50
+ case PASSWORD_RESET_CONFIRM_FAIL:
51
+ case PASSWORD_RESET_FAIL:
52
+ return __assign(__assign({}, state), { error: payload });
53
+ case CLEAR_ERRORS:
54
+ return __assign(__assign({}, state), { error: null, status: null });
55
+ default:
56
+ return state;
57
+ }
58
+ }
@@ -0,0 +1,7 @@
1
+ declare const rootReducer: import("redux").Reducer<{
2
+ auth: import("./authReducer").AuthState;
3
+ }, any, Partial<{
4
+ auth: import("./authReducer").AuthState | undefined;
5
+ }>>;
6
+ export type RootState = ReturnType<typeof rootReducer>;
7
+ export default rootReducer;
@@ -0,0 +1,6 @@
1
+ import { combineReducers } from 'redux';
2
+ import auth from './authReducer';
3
+ var rootReducer = combineReducers({
4
+ auth: auth,
5
+ });
6
+ export default rootReducer;
@@ -0,0 +1,4 @@
1
+ import { AuthStorage } from "../actions/types";
2
+ export declare const setupAuth: (storage: AuthStorage) => {
3
+ initialize: () => void;
4
+ };