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
@@ -0,0 +1,111 @@
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 * as Keychain from 'react-native-keychain';
38
+ import AsyncStorage from '@react-native-async-storage/async-storage';
39
+ var ACCESS_KEY = 'access';
40
+ export var storage = {
41
+ /**
42
+ * 🔑 Access token (fast access)
43
+ */
44
+ getAccessToken: function () { return __awaiter(void 0, void 0, void 0, function () {
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0: return [4 /*yield*/, AsyncStorage.getItem(ACCESS_KEY)];
48
+ case 1: return [2 /*return*/, _a.sent()];
49
+ }
50
+ });
51
+ }); },
52
+ /**
53
+ * 🔁 Refresh token (SECURED with biometrics)
54
+ */
55
+ getRefreshToken: function () { return __awaiter(void 0, void 0, void 0, function () {
56
+ var credentials;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0: return [4 /*yield*/, Keychain.getGenericPassword({
60
+ authenticationPrompt: {
61
+ title: 'Authenticate to continue',
62
+ },
63
+ })];
64
+ case 1:
65
+ credentials = _a.sent();
66
+ if (!credentials)
67
+ return [2 /*return*/, null];
68
+ return [2 /*return*/, credentials.password]; // refresh token
69
+ }
70
+ });
71
+ }); },
72
+ /**
73
+ * 💾 Save tokens
74
+ */
75
+ setTokens: function (access, refresh) { return __awaiter(void 0, void 0, void 0, function () {
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0: return [4 /*yield*/, AsyncStorage.setItem(ACCESS_KEY, access)];
79
+ case 1:
80
+ _a.sent();
81
+ if (!refresh) return [3 /*break*/, 3];
82
+ return [4 /*yield*/, Keychain.setGenericPassword('refreshToken', // username (not important)
83
+ refresh, {
84
+ accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE,
85
+ accessible: Keychain.ACCESSIBLE.WHEN_UNLOCKED,
86
+ // authenticationType: Keychain.AUTHENTICATION_TYPE.BIOMETRICS,
87
+ })];
88
+ case 2:
89
+ _a.sent();
90
+ _a.label = 3;
91
+ case 3: return [2 /*return*/];
92
+ }
93
+ });
94
+ }); },
95
+ /**
96
+ * 🧹 Clear tokens
97
+ */
98
+ clearTokens: function () { return __awaiter(void 0, void 0, void 0, function () {
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0: return [4 /*yield*/, AsyncStorage.removeItem(ACCESS_KEY)];
102
+ case 1:
103
+ _a.sent();
104
+ return [4 /*yield*/, Keychain.resetGenericPassword()];
105
+ case 2:
106
+ _a.sent();
107
+ return [2 /*return*/];
108
+ }
109
+ });
110
+ }); },
111
+ };
@@ -0,0 +1,8 @@
1
+ declare const store: import("@reduxjs/toolkit").EnhancedStore<{
2
+ auth: import("../auth-core/reducers/authReducer").AuthState;
3
+ }, any, import("@reduxjs/toolkit").Tuple<[import("redux").StoreEnhancer<{
4
+ dispatch: import("redux-thunk").ThunkDispatch<{
5
+ auth: import("../auth-core/reducers/authReducer").AuthState;
6
+ }, undefined, import("redux").UnknownAction>;
7
+ }>, import("redux").StoreEnhancer]>>;
8
+ export default store;
@@ -0,0 +1,9 @@
1
+ import { configureStore } from '@reduxjs/toolkit';
2
+ import rootReducer from '../auth-core/reducers';
3
+ var initialState = {};
4
+ var store = configureStore({
5
+ reducer: rootReducer,
6
+ // If you want to set an initial state, use preloadedState instead:
7
+ preloadedState: initialState,
8
+ });
9
+ export default store;
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ type AuthProviderProps = {
3
+ children: React.ReactNode;
4
+ apiUrl: string;
5
+ };
6
+ declare const AuthProvider: React.FC<AuthProviderProps>;
7
+ export default AuthProvider;
@@ -0,0 +1,14 @@
1
+ import React, { useEffect } from "react";
2
+ import { Provider } from "react-redux";
3
+ import store from "../auth-native/store";
4
+ import { auth } from "./index";
5
+ import { setBaseURL } from "../auth-core/apis/config";
6
+ var AuthProvider = function (_a) {
7
+ var children = _a.children, apiUrl = _a.apiUrl;
8
+ useEffect(function () {
9
+ setBaseURL(apiUrl);
10
+ auth.initialize(); // 🔥 attach token to axios on app load
11
+ }, [apiUrl]);
12
+ return React.createElement(Provider, { store: store }, children);
13
+ };
14
+ export default AuthProvider;
@@ -0,0 +1,11 @@
1
+ import { AuthStorage } from "../../auth-core/actions/types";
2
+ interface GoogleAuthHookReturn {
3
+ continueWithGoogle: () => Promise<void>;
4
+ authenticateWithGoogle: (state: string, code: string) => Promise<void>;
5
+ isAuthenticated: boolean | null;
6
+ error: any;
7
+ isStatus201: boolean;
8
+ loading: boolean;
9
+ }
10
+ declare const useGoogleAuth: (storage: AuthStorage) => GoogleAuthHookReturn;
11
+ export default useGoogleAuth;
@@ -0,0 +1,126 @@
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 { useDispatch, useSelector } from "react-redux";
38
+ import { useEffect, useCallback, useState } from "react";
39
+ import { clearErrors } from "../../auth-core/actions/authActions";
40
+ import axios from "axios";
41
+ import { googleAuthenticate } from "../oauth/google";
42
+ import { getBaseURL } from "../../auth-core/apis/config";
43
+ // The custom hook is now typed with its parameters and return value
44
+ var useGoogleAuth = function (storage) {
45
+ // useDispatch is typed with our custom AppDispatch
46
+ var dispatch = useDispatch();
47
+ // useSelector is typed with AuthState for type-safe state access
48
+ var isAuthenticated = useSelector(function (state) { return state.auth.isAuthenticated; });
49
+ var error = useSelector(function (state) { return state.auth.error; });
50
+ var status = useSelector(function (state) { return state.auth.status; });
51
+ // useState is typed as boolean
52
+ var _a = useState(false), loading = _a[0], setLoading = _a[1];
53
+ var isStatus201 = status === 201;
54
+ // Initiate Google Login
55
+ var continueWithGoogle = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
56
+ var redirectUri, res, err_1;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0:
60
+ setLoading(true);
61
+ redirectUri = "".concat(window.location.origin, "/login");
62
+ _a.label = 1;
63
+ case 1:
64
+ _a.trys.push([1, 3, 4, 5]);
65
+ return [4 /*yield*/, axios.get("".concat(getBaseURL(), "/auth/o/google-oauth2/?redirect_uri=").concat(redirectUri))];
66
+ case 2:
67
+ res = _a.sent();
68
+ // Redirect user to Google's OAuth page
69
+ window.location.replace(res.data.authorization_url);
70
+ return [3 /*break*/, 5];
71
+ case 3:
72
+ err_1 = _a.sent();
73
+ console.error("Google Auth Failed", err_1);
74
+ return [3 /*break*/, 5];
75
+ case 4:
76
+ setLoading(false);
77
+ return [7 /*endfinally*/];
78
+ case 5: return [2 /*return*/];
79
+ }
80
+ });
81
+ }); }, []);
82
+ // Authenticate with Google after redirection
83
+ var authenticateWithGoogle = useCallback(function (state, code) { return __awaiter(void 0, void 0, void 0, function () {
84
+ var err_2;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ if (!state || !code)
89
+ return [2 /*return*/];
90
+ setLoading(true);
91
+ _a.label = 1;
92
+ case 1:
93
+ _a.trys.push([1, 3, 4, 5]);
94
+ return [4 /*yield*/, dispatch(googleAuthenticate(state, code, storage))];
95
+ case 2:
96
+ _a.sent();
97
+ return [3 /*break*/, 5];
98
+ case 3:
99
+ err_2 = _a.sent();
100
+ console.error("Authentication failed", err_2);
101
+ return [3 /*break*/, 5];
102
+ case 4:
103
+ setLoading(false);
104
+ return [7 /*endfinally*/];
105
+ case 5: return [2 /*return*/];
106
+ }
107
+ });
108
+ }); }, [dispatch, storage]);
109
+ // Clear errors when the hook is unmounted
110
+ useEffect(function () {
111
+ // Clear errors when the component mounts
112
+ dispatch(clearErrors());
113
+ return function () {
114
+ dispatch(clearErrors());
115
+ };
116
+ }, [dispatch]);
117
+ return {
118
+ continueWithGoogle: continueWithGoogle,
119
+ authenticateWithGoogle: authenticateWithGoogle,
120
+ isAuthenticated: isAuthenticated,
121
+ error: error,
122
+ isStatus201: isStatus201,
123
+ loading: loading,
124
+ };
125
+ };
126
+ export default useGoogleAuth;
@@ -0,0 +1,6 @@
1
+ export declare const auth: {
2
+ initialize: () => void;
3
+ };
4
+ export { default as AuthProvider } from "./authProvider";
5
+ export { default as store } from "./store";
6
+ export { default as useGoogleAuth } from "./hooks/useGoogleAuth";
@@ -0,0 +1,6 @@
1
+ import { setupAuth } from "../auth-core/setup/setupAuth";
2
+ import { storage } from "./storage/webStorage";
3
+ export var auth = setupAuth(storage);
4
+ export { default as AuthProvider } from "./authProvider";
5
+ export { default as store } from "./store";
6
+ export { default as useGoogleAuth } from "./hooks/useGoogleAuth";
@@ -0,0 +1,3 @@
1
+ import { AppDispatch } from '../../auth-core/actions/authActions';
2
+ import { AuthStorage } from '../../auth-core/actions/types';
3
+ export declare const googleAuthenticate: (state: any, code: any, storage: AuthStorage) => (dispatch: AppDispatch) => Promise<void>;
@@ -0,0 +1,93 @@
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 axios from 'axios';
49
+ import { load_user } from '../../auth-core/actions/authActions';
50
+ import { GOOGLE_AUTH_FAIL, GOOGLE_AUTH_SUCCESS, } from '../../auth-core/actions/types';
51
+ import { getBaseURL } from '../../auth-core/apis/config';
52
+ export var googleAuthenticate = function (state, code, storage) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
53
+ var config, details_1, formBody, res, err_1, error;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0:
57
+ if (!(state && code && !localStorage.getItem('access'))) return [3 /*break*/, 4];
58
+ config = {
59
+ headers: {
60
+ 'Content-Type': 'application/x-www-form-urlencoded'
61
+ }
62
+ };
63
+ details_1 = {
64
+ 'state': state,
65
+ 'code': code
66
+ };
67
+ formBody = Object.keys(details_1).map(function (key) { return encodeURIComponent(key) + '=' + encodeURIComponent(details_1[key]); }).join('&');
68
+ _a.label = 1;
69
+ case 1:
70
+ _a.trys.push([1, 3, , 4]);
71
+ return [4 /*yield*/, axios.post("".concat(getBaseURL(), "/auth/o/google-oauth2/?").concat(formBody), config)];
72
+ case 2:
73
+ res = _a.sent();
74
+ dispatch({
75
+ type: GOOGLE_AUTH_SUCCESS,
76
+ payload: __assign(__assign({}, res.data), { status: res.status })
77
+ });
78
+ dispatch(load_user(storage));
79
+ return [3 /*break*/, 4];
80
+ case 3:
81
+ err_1 = _a.sent();
82
+ error = err_1;
83
+ if (error.response) {
84
+ dispatch({
85
+ type: GOOGLE_AUTH_FAIL,
86
+ payload: error.response.data
87
+ });
88
+ }
89
+ return [3 /*break*/, 4];
90
+ case 4: return [2 /*return*/];
91
+ }
92
+ });
93
+ }); }; };
@@ -0,0 +1,5 @@
1
+ export declare const storage: {
2
+ getAccessToken: () => string | null;
3
+ setTokens: (access: string, refresh?: string) => void;
4
+ clearTokens: () => void;
5
+ };
@@ -0,0 +1,13 @@
1
+ export var storage = {
2
+ getAccessToken: function () { return localStorage.getItem('access'); },
3
+ setTokens: function (access, refresh) {
4
+ localStorage.setItem('access', access);
5
+ if (refresh) {
6
+ localStorage.setItem('refresh', refresh);
7
+ }
8
+ },
9
+ clearTokens: function () {
10
+ localStorage.removeItem('access');
11
+ localStorage.removeItem('refresh');
12
+ }
13
+ };
@@ -0,0 +1,8 @@
1
+ declare const store: import("@reduxjs/toolkit").EnhancedStore<{
2
+ auth: import("../auth-core/reducers/authReducer").AuthState;
3
+ }, any, import("@reduxjs/toolkit").Tuple<[import("redux").StoreEnhancer<{
4
+ dispatch: import("redux-thunk").ThunkDispatch<{
5
+ auth: import("../auth-core/reducers/authReducer").AuthState;
6
+ }, undefined, import("redux").UnknownAction>;
7
+ }>, import("redux").StoreEnhancer]>>;
8
+ export default store;
@@ -0,0 +1,9 @@
1
+ import { configureStore } from '@reduxjs/toolkit';
2
+ import rootReducer from '../auth-core/reducers';
3
+ var initialState = {};
4
+ var store = configureStore({
5
+ reducer: rootReducer,
6
+ // If you want to set an initial state, use preloadedState instead:
7
+ preloadedState: initialState,
8
+ });
9
+ export default store;
package/dist/index.d.mts CHANGED
@@ -1,150 +1,31 @@
1
- import React$1 from 'react';
1
+ import React from 'react';
2
+ import * as _reduxjs_toolkit from '@reduxjs/toolkit';
3
+ import * as redux_thunk from 'redux-thunk';
4
+ import * as redux from 'redux';
2
5
 
3
- interface ActivateHookReturn {
4
- loading: boolean;
5
- error: any;
6
- onSubmit: (e: React.FormEvent) => Promise<void>;
7
- status: any;
8
- isStatus204: boolean;
9
- }
10
- declare const useActivate: (uid: string, token: string, apiUrl: string) => ActivateHookReturn;
6
+ declare const AuthProviderNative: ({ children }: any) => React.JSX.Element;
11
7
 
12
- interface LoginHookReturn {
13
- loading: boolean;
14
- formData: any;
15
- error: any;
16
- currentUser: any;
17
- onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
18
- onSubmit: (e: React.FormEvent) => Promise<void>;
19
- isAuthenticated: boolean | null;
20
- isStatus200: boolean;
21
- }
22
- declare const useLogin: (initialFields: any, apiUrl: string, location: any) => LoginHookReturn;
23
-
24
- declare const useLogout: () => (() => void);
25
-
26
- interface SignupHookReturn {
27
- loading: boolean;
28
- formData: any;
29
- error: any;
30
- onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
31
- onSubmit: (e: React.FormEvent) => Promise<void>;
8
+ interface AuthState {
9
+ access: string | null;
10
+ refresh: string | null;
32
11
  isAuthenticated: boolean | null;
33
- status: any;
34
- isStatus201: boolean;
35
- }
36
- declare const useSignup: (initialFields: any, apiUrl: string, location: any) => SignupHookReturn;
37
-
38
- interface AuthHookReturn {
39
- error: any;
40
- isAuthenticated: boolean | null;
41
- currentUser: any;
42
- clearErrors: () => void;
43
- refreshUser: () => void;
44
- refreshAuth: () => Promise<void>;
45
- isLoading: boolean;
46
- }
47
- declare const useAuthicatedUser: (apiURL: string, location: any) => AuthHookReturn;
48
-
49
- interface ResetPasswordHookReturn {
50
- email: string;
51
- loading: boolean;
52
- handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
53
- status: any;
12
+ user: any;
54
13
  error: any;
55
- handleSubmit: (e: React.FormEvent) => Promise<void>;
56
- isStatus204: boolean;
57
- }
58
- declare const useResetPassword: (apiUrl: string) => ResetPasswordHookReturn;
59
-
60
- interface FormData$1 {
61
- new_password?: string;
62
- re_new_password?: string;
63
- uid?: string;
64
- token?: string;
65
- }
66
- interface PasswordConfirmHookReturn {
67
- loading: boolean;
68
- formData: FormData$1;
69
- error: any;
70
- onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
71
- onSubmit: (e: React.FormEvent) => Promise<void>;
72
14
  status: any;
73
- isStatus204: boolean;
74
15
  }
75
- declare const usePasswordConfirm: (initialFields: FormData$1, apiUrl: string) => PasswordConfirmHookReturn;
76
16
 
77
- interface FormData {
78
- current_password?: string;
79
- new_password?: string;
80
- re_new_password?: string;
81
- }
82
- interface ChangePasswordHookReturn {
83
- loading: boolean;
84
- formData: FormData;
85
- error: string | null;
86
- onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
87
- onSubmit: (e: React.FormEvent) => Promise<void>;
88
- status: any;
89
- }
90
- declare const useChangeAuthenticatedUserPassword: (initialFields: FormData, apiUrl: string) => ChangePasswordHookReturn;
91
-
92
- interface GoogleAuthHookReturn {
93
- continueWithGoogle: () => Promise<void>;
94
- authenticateWithGoogle: (state: string, code: string) => Promise<void>;
95
- isAuthenticated: boolean | null;
96
- error: any;
97
- isStatus201: boolean;
98
- loading: boolean;
99
- }
100
- declare const useGoogleAuth: (apiUrl: string) => GoogleAuthHookReturn;
101
-
102
- interface FacebookAuthHookReturn {
103
- continueWithFacebook: () => Promise<void>;
104
- authenticateWithFacebook: (state: string, code: string) => Promise<void>;
105
- isAuthenticated: boolean | null;
106
- error: any;
107
- isStatus201: boolean;
108
- loading: boolean;
109
- }
110
- declare const useFacebookAuth: (apiUrl: string) => FacebookAuthHookReturn;
111
-
112
- type AuthProviderProps = {
113
- children: React$1.ReactNode;
114
- };
115
- declare const AuthProvider: React$1.FC<AuthProviderProps>;
17
+ declare const store: _reduxjs_toolkit.EnhancedStore<{
18
+ auth: AuthState;
19
+ }, any, _reduxjs_toolkit.Tuple<[redux.StoreEnhancer<{
20
+ dispatch: redux_thunk.ThunkDispatch<{
21
+ auth: AuthState;
22
+ }, undefined, redux.UnknownAction>;
23
+ }>, redux.StoreEnhancer]>>;
116
24
 
117
- /**
118
- * A type representing a single error message string.
119
- */
120
- type ErrorMessage = string;
121
- /**
122
- * A type representing an array of error messages.
123
- */
124
- type ErrorMessageArray = string[];
125
- /**
126
- * A type representing an object where keys map to either a single error message
127
- * or an array of error messages.
128
- */
129
- type ErrorMessageObject = {
130
- [key: string]: ErrorMessage | ErrorMessageArray;
25
+ declare const auth: {
26
+ initialize: () => Promise<void>;
27
+ setAuthToken: (token: string) => void;
28
+ clearAuthToken: () => void;
131
29
  };
132
- /**
133
- * A union type for all possible error message inputs.
134
- */
135
- type ErrorMessageType = ErrorMessage | ErrorMessageArray | ErrorMessageObject;
136
- /**
137
- * Extracts and flattens various error message formats into a single array of strings.
138
- *
139
- * This function can handle:
140
- * - A single string: Returns an array with that string.
141
- * - An array of strings: Returns the array as is.
142
- * - An object: Iterates through the object's values and extracts all strings
143
- * and strings from arrays into a single flattened array.
144
- *
145
- * @param errorMsg The error message(s) to extract, which can be a string, array, or object.
146
- * @returns A flattened array of error message strings.
147
- */
148
- declare const extractErrorMessages: (errorMsg: ErrorMessageType) => string[];
149
30
 
150
- export { AuthProvider, extractErrorMessages, useActivate, useAuthicatedUser, useChangeAuthenticatedUserPassword, useFacebookAuth, useGoogleAuth, useLogin, useLogout, usePasswordConfirm, useResetPassword, useSignup };
31
+ export { AuthProviderNative as AuthProvider, auth, store };