react-redux-django-auth 1.4.5 → 1.4.7

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 +93 -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 +7 -0
  47. package/dist/auth-native/index.js +7 -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 -2114
  67. package/dist/index.mjs +72 -844
  68. package/package.json +42 -7
package/README.md CHANGED
@@ -603,3 +603,96 @@ const DashboardLayout = () => {
603
603
  );
604
604
  };
605
605
  ```
606
+ ## React Native Usage
607
+ #### Setting Auth Provider
608
+
609
+ ```
610
+ import { Slot } from "expo-router";
611
+ import AuthProviderNative from "./auth/AuthProviderNative";
612
+
613
+ export default function RootLayout() {
614
+ // Replace with your actual backend URL
615
+ const API_URL = "https://api.yourdomain.com/v1";
616
+
617
+ return (
618
+ <AuthProviderNative apiUrl={API_URL}>
619
+ <Slot />
620
+ </AuthProviderNative>
621
+ );
622
+ }
623
+ ```
624
+
625
+ #### useBiometric hook
626
+ ```
627
+ import React, { useEffect } from "react";
628
+ import { View, ActivityIndicator, Text } from "react-native";
629
+ import { useAuthicatedUser } from "../hooks/useAuthicatedUser";
630
+ import useBiometricAuth from "../hooks/useBiometricAuth";
631
+ import { storage } from "../auth-core/storage";
632
+ import { API_URL } from "../config";
633
+ import { useNavigation } from "@react-navigation/native";
634
+
635
+ const SplashScreen = () => {
636
+ const navigation = useNavigation();
637
+
638
+ const { isAuthenticated, currentUser, isLoading, refreshAuth } =
639
+ useAuthicatedUser(API_URL, null, storage);
640
+
641
+ const { authenticate, loading: bioLoading } = useBiometricAuth({
642
+ storage,
643
+ apiUrl: API_URL,
644
+ });
645
+
646
+ useEffect(() => {
647
+ const initAuth = async () => {
648
+ try {
649
+ // 1️⃣ Attempt biometric login if not already authenticated
650
+ if (!isAuthenticated) {
651
+ await authenticate(); // this will handle refresh token internally
652
+ await refreshAuth(); // re-check auth + load user into redux
653
+ }
654
+
655
+ // 2️⃣ Navigate based on user role
656
+ if (currentUser) {
657
+ switch (currentUser.role) {
658
+ case "admin":
659
+ case "superadmin":
660
+ navigation.reset({ index: 0, routes: [{ name: "AdminHome" }] });
661
+ break;
662
+ case "vendor":
663
+ navigation.reset({ index: 0, routes: [{ name: "VendorDashboard" }] });
664
+ break;
665
+ case "customer":
666
+ navigation.reset({ index: 0, routes: [{ name: "CustomerMain" }] });
667
+ break;
668
+ default:
669
+ navigation.reset({ index: 0, routes: [{ name: "Login" }] });
670
+ }
671
+ } else {
672
+ navigation.reset({ index: 0, routes: [{ name: "Login" }] });
673
+ }
674
+ } catch (err) {
675
+ console.log("Biometric/Auth failed:", err);
676
+ navigation.reset({ index: 0, routes: [{ name: "Login" }] });
677
+ }
678
+ };
679
+
680
+ initAuth();
681
+ }, [isAuthenticated, currentUser]);
682
+
683
+ // Show loading while checking authentication
684
+ if (isLoading || bioLoading) {
685
+ return (
686
+ <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
687
+ <ActivityIndicator size="large" />
688
+ <Text>Loading...</Text>
689
+ </View>
690
+ );
691
+ }
692
+
693
+ return null; // navigation will replace this
694
+ };
695
+
696
+ export default SplashScreen;
697
+
698
+ ```
@@ -0,0 +1,57 @@
1
+ import { Dispatch } from 'redux';
2
+ import { AuthStorage } from './types';
3
+ export type AppDispatch = Dispatch<any>;
4
+ /**
5
+ * Load Authenticated User
6
+ */
7
+ export declare const load_user: (storage: AuthStorage) => (dispatch: AppDispatch) => Promise<{
8
+ type: string;
9
+ } | undefined>;
10
+ /**
11
+ * Facebook Auth
12
+ */
13
+ export declare const facebookAuthenticate: (state: any, code: any, storage: AuthStorage) => (dispatch: AppDispatch) => Promise<void>;
14
+ /**
15
+ * Check Authentication
16
+ */
17
+ export declare const checkAuthenticated: (storage: AuthStorage) => (dispatch: AppDispatch) => Promise<{
18
+ type: string;
19
+ } | undefined>;
20
+ /**
21
+ * Login
22
+ */
23
+ export declare const login: (formData: any, storage: AuthStorage) => (dispatch: AppDispatch) => Promise<void>;
24
+ /**
25
+ * Signup
26
+ */
27
+ export declare const signup: (formData: any) => (dispatch: AppDispatch) => Promise<void>;
28
+ /**
29
+ * Verify Account
30
+ */
31
+ export declare const verify: (uid: any, token: any) => (dispatch: AppDispatch) => Promise<void>;
32
+ /**
33
+ * Reset Password
34
+ */
35
+ export declare const reset_password: (email: string) => (dispatch: AppDispatch) => Promise<void>;
36
+ /**
37
+ * Confirm Password Reset
38
+ */
39
+ export declare const reset_password_confirm: (formData: any) => (dispatch: AppDispatch) => Promise<void>;
40
+ /**
41
+ * Logout
42
+ */
43
+ export declare const logout: (storage: AuthStorage) => (dispatch: AppDispatch) => Promise<void>;
44
+ /**
45
+ * Clear Errors
46
+ */
47
+ export declare const clearErrors: () => (dispatch: AppDispatch) => void;
48
+ /**
49
+ * Change Password (Authenticated)
50
+ */
51
+ export declare const changeLoggedInUserPassword: (formData: any, storage: AuthStorage) => (dispatch: AppDispatch) => Promise<{
52
+ type: string;
53
+ } | undefined>;
54
+ /**
55
+ * 🔄 Refresh Access Token
56
+ */
57
+ export declare const refreshAccessToken: (storage: AuthStorage) => (dispatch: AppDispatch) => Promise<any>;
@@ -0,0 +1,451 @@
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 axios from 'axios';
38
+ 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, FACEBOOK_AUTH_SUCCESS, FACEBOOK_AUTH_FAIL, LOGOUT, CLEAR_ERRORS } from './types';
39
+ import { getBaseURL } from '../apis/config';
40
+ /**
41
+ * 🔥 Helper: Get Auth Header
42
+ */
43
+ var getAuthConfig = function (storage) { return __awaiter(void 0, void 0, void 0, function () {
44
+ var token;
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0: return [4 /*yield*/, storage.getAccessToken()];
48
+ case 1:
49
+ token = _a.sent();
50
+ if (!token)
51
+ return [2 /*return*/, null];
52
+ return [2 /*return*/, {
53
+ headers: {
54
+ Authorization: "JWT ".concat(token),
55
+ 'Content-Type': 'application/json'
56
+ }
57
+ }];
58
+ }
59
+ });
60
+ }); };
61
+ /**
62
+ * Load Authenticated User
63
+ */
64
+ export var load_user = function (storage) {
65
+ return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
66
+ var config, res, _a;
67
+ return __generator(this, function (_b) {
68
+ switch (_b.label) {
69
+ case 0: return [4 /*yield*/, getAuthConfig(storage)];
70
+ case 1:
71
+ config = _b.sent();
72
+ if (!config) {
73
+ return [2 /*return*/, dispatch({ type: USER_LOADED_FAIL })];
74
+ }
75
+ _b.label = 2;
76
+ case 2:
77
+ _b.trys.push([2, 4, , 5]);
78
+ return [4 /*yield*/, axios.get("".concat(getBaseURL(), "/auth/users/me/"), config)];
79
+ case 3:
80
+ res = _b.sent();
81
+ dispatch({
82
+ type: USER_LOADED_SUCCESS,
83
+ payload: res.data
84
+ });
85
+ return [3 /*break*/, 5];
86
+ case 4:
87
+ _a = _b.sent();
88
+ dispatch({ type: USER_LOADED_FAIL });
89
+ return [3 /*break*/, 5];
90
+ case 5: return [2 /*return*/];
91
+ }
92
+ });
93
+ }); };
94
+ };
95
+ /**
96
+ * Facebook Auth
97
+ */
98
+ export var facebookAuthenticate = function (state, code, storage) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
99
+ var token, res, _a, access, refresh, err_1;
100
+ var _b;
101
+ return __generator(this, function (_c) {
102
+ switch (_c.label) {
103
+ case 0: return [4 /*yield*/, storage.getAccessToken()];
104
+ case 1:
105
+ token = _c.sent();
106
+ if (!(state && code && !token)) return [3 /*break*/, 6];
107
+ _c.label = 2;
108
+ case 2:
109
+ _c.trys.push([2, 5, , 6]);
110
+ return [4 /*yield*/, axios.post("".concat(getBaseURL(), "/auth/o/facebook/?state=").concat(state, "&code=").concat(code), {}, {
111
+ headers: {
112
+ 'Content-Type': 'application/x-www-form-urlencoded'
113
+ }
114
+ })];
115
+ case 3:
116
+ res = _c.sent();
117
+ _a = res.data, access = _a.access, refresh = _a.refresh;
118
+ return [4 /*yield*/, storage.setTokens(access, refresh)];
119
+ case 4:
120
+ _c.sent();
121
+ dispatch({
122
+ type: FACEBOOK_AUTH_SUCCESS,
123
+ payload: res.data
124
+ });
125
+ dispatch(load_user(storage));
126
+ return [3 /*break*/, 6];
127
+ case 5:
128
+ err_1 = _c.sent();
129
+ dispatch({
130
+ type: FACEBOOK_AUTH_FAIL,
131
+ payload: (_b = err_1 === null || err_1 === void 0 ? void 0 : err_1.response) === null || _b === void 0 ? void 0 : _b.data
132
+ });
133
+ return [3 /*break*/, 6];
134
+ case 6: return [2 /*return*/];
135
+ }
136
+ });
137
+ }); }; };
138
+ /**
139
+ * Check Authentication
140
+ */
141
+ export var checkAuthenticated = function (storage) {
142
+ return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
143
+ var token, res, _a;
144
+ return __generator(this, function (_b) {
145
+ switch (_b.label) {
146
+ case 0: return [4 /*yield*/, storage.getAccessToken()];
147
+ case 1:
148
+ token = _b.sent();
149
+ if (!token) {
150
+ return [2 /*return*/, dispatch({ type: AUTHENTICATED_FAIL })];
151
+ }
152
+ _b.label = 2;
153
+ case 2:
154
+ _b.trys.push([2, 4, , 5]);
155
+ return [4 /*yield*/, axios.post("".concat(getBaseURL(), "/auth/jwt/verify/"), { token: token })];
156
+ case 3:
157
+ res = _b.sent();
158
+ dispatch({
159
+ type: res.data.code !== 'token_not_valid'
160
+ ? AUTHENTICATED_SUCCESS
161
+ : AUTHENTICATED_FAIL
162
+ });
163
+ return [3 /*break*/, 5];
164
+ case 4:
165
+ _a = _b.sent();
166
+ dispatch({ type: AUTHENTICATED_FAIL });
167
+ return [3 /*break*/, 5];
168
+ case 5: return [2 /*return*/];
169
+ }
170
+ });
171
+ }); };
172
+ };
173
+ /**
174
+ * Login
175
+ */
176
+ export var login = function (formData, storage) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
177
+ var res, _a, access, refresh, err_2;
178
+ var _b;
179
+ return __generator(this, function (_c) {
180
+ switch (_c.label) {
181
+ case 0:
182
+ _c.trys.push([0, 3, , 4]);
183
+ return [4 /*yield*/, axios.post("".concat(getBaseURL(), "/auth/jwt/create/"), formData)];
184
+ case 1:
185
+ res = _c.sent();
186
+ _a = res.data, access = _a.access, refresh = _a.refresh;
187
+ return [4 /*yield*/, storage.setTokens(access, refresh)];
188
+ case 2:
189
+ _c.sent();
190
+ dispatch({
191
+ type: LOGIN_SUCCESS,
192
+ payload: {
193
+ access: access,
194
+ refresh: refresh,
195
+ status: res.status
196
+ }
197
+ });
198
+ dispatch(load_user(storage));
199
+ return [3 /*break*/, 4];
200
+ case 3:
201
+ err_2 = _c.sent();
202
+ dispatch({
203
+ type: LOGIN_FAIL,
204
+ payload: (_b = err_2 === null || err_2 === void 0 ? void 0 : err_2.response) === null || _b === void 0 ? void 0 : _b.data
205
+ });
206
+ return [3 /*break*/, 4];
207
+ case 4: return [2 /*return*/];
208
+ }
209
+ });
210
+ }); }; };
211
+ /**
212
+ * Signup
213
+ */
214
+ export var signup = function (formData) {
215
+ return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
216
+ var res, err_3;
217
+ var _a;
218
+ return __generator(this, function (_b) {
219
+ switch (_b.label) {
220
+ case 0:
221
+ _b.trys.push([0, 2, , 3]);
222
+ return [4 /*yield*/, axios.post("".concat(getBaseURL(), "/auth/users/"), formData, {
223
+ headers: {
224
+ 'Content-Type': 'application/json'
225
+ }
226
+ })];
227
+ case 1:
228
+ res = _b.sent();
229
+ dispatch({
230
+ type: SIGNUP_SUCCESS,
231
+ payload: res.status
232
+ });
233
+ return [3 /*break*/, 3];
234
+ case 2:
235
+ err_3 = _b.sent();
236
+ dispatch({
237
+ type: SIGNUP_FAIL,
238
+ payload: (_a = err_3 === null || err_3 === void 0 ? void 0 : err_3.response) === null || _a === void 0 ? void 0 : _a.data
239
+ });
240
+ return [3 /*break*/, 3];
241
+ case 3: return [2 /*return*/];
242
+ }
243
+ });
244
+ }); };
245
+ };
246
+ /**
247
+ * Verify Account
248
+ */
249
+ export var verify = function (uid, token) {
250
+ return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
251
+ var res, err_4;
252
+ var _a;
253
+ return __generator(this, function (_b) {
254
+ switch (_b.label) {
255
+ case 0:
256
+ _b.trys.push([0, 2, , 3]);
257
+ return [4 /*yield*/, axios.post("".concat(getBaseURL(), "/auth/users/activation/"), { uid: uid, token: token })];
258
+ case 1:
259
+ res = _b.sent();
260
+ dispatch({
261
+ type: ACTIVATION_SUCCESS,
262
+ payload: res.status
263
+ });
264
+ return [3 /*break*/, 3];
265
+ case 2:
266
+ err_4 = _b.sent();
267
+ dispatch({
268
+ type: ACTIVATION_FAIL,
269
+ payload: (_a = err_4 === null || err_4 === void 0 ? void 0 : err_4.response) === null || _a === void 0 ? void 0 : _a.data
270
+ });
271
+ return [3 /*break*/, 3];
272
+ case 3: return [2 /*return*/];
273
+ }
274
+ });
275
+ }); };
276
+ };
277
+ /**
278
+ * Reset Password
279
+ */
280
+ export var reset_password = function (email) {
281
+ return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
282
+ var res, err_5;
283
+ var _a;
284
+ return __generator(this, function (_b) {
285
+ switch (_b.label) {
286
+ case 0:
287
+ _b.trys.push([0, 2, , 3]);
288
+ return [4 /*yield*/, axios.post("".concat(getBaseURL(), "/auth/users/reset_password/"), { email: email })];
289
+ case 1:
290
+ res = _b.sent();
291
+ dispatch({
292
+ type: PASSWORD_RESET_SUCCESS,
293
+ payload: res.status
294
+ });
295
+ return [3 /*break*/, 3];
296
+ case 2:
297
+ err_5 = _b.sent();
298
+ dispatch({
299
+ type: PASSWORD_RESET_FAIL,
300
+ payload: (_a = err_5 === null || err_5 === void 0 ? void 0 : err_5.response) === null || _a === void 0 ? void 0 : _a.data
301
+ });
302
+ return [3 /*break*/, 3];
303
+ case 3: return [2 /*return*/];
304
+ }
305
+ });
306
+ }); };
307
+ };
308
+ /**
309
+ * Confirm Password Reset
310
+ */
311
+ export var reset_password_confirm = function (formData) {
312
+ return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
313
+ var res, err_6;
314
+ var _a;
315
+ return __generator(this, function (_b) {
316
+ switch (_b.label) {
317
+ case 0:
318
+ _b.trys.push([0, 2, , 3]);
319
+ return [4 /*yield*/, axios.post("".concat(getBaseURL(), "/auth/users/reset_password_confirm/"), formData)];
320
+ case 1:
321
+ res = _b.sent();
322
+ dispatch({
323
+ type: PASSWORD_RESET_CONFIRM_SUCCESS,
324
+ payload: res.status
325
+ });
326
+ return [3 /*break*/, 3];
327
+ case 2:
328
+ err_6 = _b.sent();
329
+ dispatch({
330
+ type: PASSWORD_RESET_CONFIRM_FAIL,
331
+ payload: (_a = err_6 === null || err_6 === void 0 ? void 0 : err_6.response) === null || _a === void 0 ? void 0 : _a.data
332
+ });
333
+ return [3 /*break*/, 3];
334
+ case 3: return [2 /*return*/];
335
+ }
336
+ });
337
+ }); };
338
+ };
339
+ /**
340
+ * Logout
341
+ */
342
+ export var logout = function (storage) {
343
+ return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
344
+ return __generator(this, function (_a) {
345
+ switch (_a.label) {
346
+ case 0: return [4 /*yield*/, storage.clearTokens()];
347
+ case 1:
348
+ _a.sent();
349
+ dispatch({ type: LOGOUT });
350
+ return [2 /*return*/];
351
+ }
352
+ });
353
+ }); };
354
+ };
355
+ /**
356
+ * Clear Errors
357
+ */
358
+ export var clearErrors = function () { return function (dispatch) {
359
+ dispatch({ type: CLEAR_ERRORS });
360
+ }; };
361
+ /**
362
+ * Change Password (Authenticated)
363
+ */
364
+ export var changeLoggedInUserPassword = function (formData, storage) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
365
+ var config, res, err_7;
366
+ var _a;
367
+ return __generator(this, function (_b) {
368
+ switch (_b.label) {
369
+ case 0: return [4 /*yield*/, getAuthConfig(storage)];
370
+ case 1:
371
+ config = _b.sent();
372
+ if (!config) {
373
+ return [2 /*return*/, dispatch({ type: AUTHENTICATED_FAIL })];
374
+ }
375
+ _b.label = 2;
376
+ case 2:
377
+ _b.trys.push([2, 4, , 5]);
378
+ return [4 /*yield*/, axios.post("".concat(getBaseURL(), "/auth/users/set_password/"), formData, config)];
379
+ case 3:
380
+ res = _b.sent();
381
+ dispatch({
382
+ type: PASSWORD_RESET_SUCCESS,
383
+ payload: res.data
384
+ });
385
+ return [3 /*break*/, 5];
386
+ case 4:
387
+ err_7 = _b.sent();
388
+ dispatch({
389
+ type: PASSWORD_RESET_FAIL,
390
+ payload: (_a = err_7 === null || err_7 === void 0 ? void 0 : err_7.response) === null || _a === void 0 ? void 0 : _a.data
391
+ });
392
+ return [3 /*break*/, 5];
393
+ case 5: return [2 /*return*/];
394
+ }
395
+ });
396
+ }); }; };
397
+ /**
398
+ * 🔄 Refresh Access Token
399
+ */
400
+ export var refreshAccessToken = function (storage) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
401
+ var refresh, res, access, err_8;
402
+ var _a;
403
+ return __generator(this, function (_b) {
404
+ switch (_b.label) {
405
+ case 0:
406
+ _b.trys.push([0, 6, , 8]);
407
+ return [4 /*yield*/, ((_a = storage.getRefreshToken) === null || _a === void 0 ? void 0 : _a.call(storage))];
408
+ case 1:
409
+ refresh = _b.sent();
410
+ if (!!refresh) return [3 /*break*/, 3];
411
+ return [4 /*yield*/, storage.clearTokens()];
412
+ case 2:
413
+ _b.sent();
414
+ return [2 /*return*/, dispatch({
415
+ type: AUTHENTICATED_FAIL
416
+ })];
417
+ case 3: return [4 /*yield*/, axios.post("".concat(getBaseURL(), "/auth/jwt/refresh/"), { refresh: refresh })];
418
+ case 4:
419
+ res = _b.sent();
420
+ access = res.data.access;
421
+ // 💾 Save new access token (keep existing refresh)
422
+ return [4 /*yield*/, storage.setTokens(access, refresh)];
423
+ case 5:
424
+ // 💾 Save new access token (keep existing refresh)
425
+ _b.sent();
426
+ dispatch({
427
+ type: LOGIN_SUCCESS, // reuse existing flow
428
+ payload: {
429
+ access: access,
430
+ refresh: refresh,
431
+ status: res.status
432
+ }
433
+ });
434
+ // 🔄 Reload user after refresh
435
+ dispatch(load_user(storage));
436
+ return [2 /*return*/, access];
437
+ case 6:
438
+ err_8 = _b.sent();
439
+ // ❌ Refresh failed → logout user completely
440
+ return [4 /*yield*/, storage.clearTokens()];
441
+ case 7:
442
+ // ❌ Refresh failed → logout user completely
443
+ _b.sent();
444
+ dispatch({
445
+ type: AUTHENTICATED_FAIL
446
+ });
447
+ return [2 /*return*/, null];
448
+ case 8: return [2 /*return*/];
449
+ }
450
+ });
451
+ }); }; };
@@ -0,0 +1,26 @@
1
+ export declare const LOGIN_SUCCESS = "LOGIN_SUCCESS";
2
+ export declare const LOGIN_FAIL = "LOGIN_FAIL";
3
+ export declare const USER_LOADED_SUCCESS = "USER_LOADED_SUCCESS";
4
+ export declare const USER_LOADED_FAIL = "USER_LOADED_FAIL";
5
+ export declare const AUTHENTICATED_SUCCESS = "AUTHENTICATED_SUCCESS";
6
+ export declare const AUTHENTICATED_FAIL = "AUTHENTICATED_FAIL";
7
+ export declare const PASSWORD_RESET_SUCCESS = "PASSWORD_RESET_SUCCESS";
8
+ export declare const PASSWORD_RESET_FAIL = "PASSWORD_RESET_FAIL";
9
+ export declare const PASSWORD_RESET_CONFIRM_SUCCESS = "PASSWORD_RESET_CONFIRM_SUCCESS";
10
+ export declare const PASSWORD_RESET_CONFIRM_FAIL = "PASSWORD_RESET_CONFIRM_FAIL";
11
+ export declare const SIGNUP_SUCCESS = "SIGNUP_SUCCESS";
12
+ export declare const SIGNUP_FAIL = "SIGNUP_FAIL";
13
+ export declare const ACTIVATION_SUCCESS = "ACTIVATION_SUCCESS";
14
+ export declare const ACTIVATION_FAIL = "ACTIVATION_FAIL";
15
+ export declare const GOOGLE_AUTH_SUCCESS = "GOOGLE_AUTH_SUCCESS";
16
+ export declare const GOOGLE_AUTH_FAIL = "GOOGLE_AUTH_FAIL";
17
+ export declare const FACEBOOK_AUTH_SUCCESS = "FACEBOOK_AUTH_SUCCESS";
18
+ export declare const FACEBOOK_AUTH_FAIL = "FACEBOOK_AUTH_FAIL";
19
+ export declare const LOGOUT = "LOGOUT";
20
+ export declare const CLEAR_ERRORS = "CLEAR_ERRORS";
21
+ export interface AuthStorage {
22
+ getAccessToken: () => Promise<string | null> | string | null;
23
+ getRefreshToken?: () => Promise<string | null> | string | null;
24
+ setTokens: (access: string, refresh?: string) => Promise<void> | void;
25
+ clearTokens: () => Promise<void> | void;
26
+ }
@@ -0,0 +1,22 @@
1
+ // The following is an example of what your `types.ts` file should look like.
2
+ // types.ts
3
+ export var LOGIN_SUCCESS = 'LOGIN_SUCCESS';
4
+ export var LOGIN_FAIL = 'LOGIN_FAIL';
5
+ export var USER_LOADED_SUCCESS = 'USER_LOADED_SUCCESS';
6
+ export var USER_LOADED_FAIL = 'USER_LOADED_FAIL';
7
+ export var AUTHENTICATED_SUCCESS = 'AUTHENTICATED_SUCCESS';
8
+ export var AUTHENTICATED_FAIL = 'AUTHENTICATED_FAIL';
9
+ export var PASSWORD_RESET_SUCCESS = 'PASSWORD_RESET_SUCCESS';
10
+ export var PASSWORD_RESET_FAIL = 'PASSWORD_RESET_FAIL';
11
+ export var PASSWORD_RESET_CONFIRM_SUCCESS = 'PASSWORD_RESET_CONFIRM_SUCCESS';
12
+ export var PASSWORD_RESET_CONFIRM_FAIL = 'PASSWORD_RESET_CONFIRM_FAIL';
13
+ export var SIGNUP_SUCCESS = 'SIGNUP_SUCCESS';
14
+ export var SIGNUP_FAIL = 'SIGNUP_FAIL';
15
+ export var ACTIVATION_SUCCESS = 'ACTIVATION_SUCCESS';
16
+ export var ACTIVATION_FAIL = 'ACTIVATION_FAIL';
17
+ export var GOOGLE_AUTH_SUCCESS = 'GOOGLE_AUTH_SUCCESS';
18
+ export var GOOGLE_AUTH_FAIL = 'GOOGLE_AUTH_FAIL';
19
+ export var FACEBOOK_AUTH_SUCCESS = 'FACEBOOK_AUTH_SUCCESS';
20
+ export var FACEBOOK_AUTH_FAIL = 'FACEBOOK_AUTH_FAIL';
21
+ export var LOGOUT = 'LOGOUT';
22
+ export var CLEAR_ERRORS = 'CLEAR_ERRORS';
@@ -0,0 +1 @@
1
+ export declare const createApi: (baseURL: string) => import("axios").AxiosInstance;
@@ -0,0 +1,11 @@
1
+ import axios from "axios";
2
+ export var createApi = function (baseURL) {
3
+ return axios.create({
4
+ baseURL: baseURL,
5
+ timeout: 30000,
6
+ headers: {
7
+ "Content-Type": "application/json",
8
+ Accept: "application/json",
9
+ },
10
+ });
11
+ };
@@ -0,0 +1,2 @@
1
+ export declare const setBaseURL: (url: string) => void;
2
+ export declare const getBaseURL: () => string;
@@ -0,0 +1,10 @@
1
+ var BASE_URL = "";
2
+ export var setBaseURL = function (url) {
3
+ BASE_URL = url;
4
+ };
5
+ export var getBaseURL = function () {
6
+ if (!BASE_URL) {
7
+ throw new Error("API URL not set. Wrap app with AuthProvider.");
8
+ }
9
+ return BASE_URL;
10
+ };