react-redux-django-auth 1.4.8 → 1.5.0
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/auth-core/actions/authActions.d.ts +7 -7
- package/dist/auth-core/actions/authActions.js +13 -13
- package/dist/auth-core/hooks/useChangePassword.d.ts +1 -2
- package/dist/auth-core/hooks/useChangePassword.js +6 -2
- package/dist/auth-core/hooks/useFacebookAuth.d.ts +1 -2
- package/dist/auth-core/hooks/useFacebookAuth.js +4 -4
- package/dist/auth-core/hooks/useLoadUser.d.ts +1 -2
- package/dist/auth-core/hooks/useLoadUser.js +12 -10
- package/dist/auth-core/hooks/useLogin.d.ts +1 -2
- package/dist/auth-core/hooks/useLogin.js +3 -3
- package/dist/auth-core/hooks/useLogout.d.ts +1 -2
- package/dist/auth-core/hooks/useLogout.js +2 -2
- package/dist/auth-native/hooks/useBiometricAuth.js +1 -1
- package/dist/auth-native/storage/nativeStorage.js +34 -20
- package/dist/auth-native/store.d.ts +7 -1
- package/dist/auth-native/store.js +10 -1
- package/dist/auth-web/hooks/useGoogleAuth.d.ts +1 -2
- package/dist/auth-web/hooks/useGoogleAuth.js +3 -3
- package/dist/auth-web/oauth/google.d.ts +1 -1
- package/dist/auth-web/oauth/google.js +2 -2
- package/dist/auth-web/store.d.ts +6 -1
- package/dist/auth-web/store.js +10 -1
- package/package.json +1 -1
|
@@ -4,23 +4,23 @@ export type AppDispatch = Dispatch<any>;
|
|
|
4
4
|
/**
|
|
5
5
|
* Load Authenticated User
|
|
6
6
|
*/
|
|
7
|
-
export declare const load_user: (
|
|
7
|
+
export declare const load_user: () => (dispatch: AppDispatch, getState: any, storage: AuthStorage) => Promise<{
|
|
8
8
|
type: string;
|
|
9
9
|
} | undefined>;
|
|
10
10
|
/**
|
|
11
11
|
* Facebook Auth
|
|
12
12
|
*/
|
|
13
|
-
export declare const facebookAuthenticate: (state: any, code: any
|
|
13
|
+
export declare const facebookAuthenticate: (state: any, code: any) => (dispatch: AppDispatch, getState: any, storage: AuthStorage) => Promise<void>;
|
|
14
14
|
/**
|
|
15
15
|
* Check Authentication
|
|
16
16
|
*/
|
|
17
|
-
export declare const checkAuthenticated: (
|
|
17
|
+
export declare const checkAuthenticated: () => (dispatch: AppDispatch, getState: any, storage: AuthStorage) => Promise<{
|
|
18
18
|
type: string;
|
|
19
19
|
} | undefined>;
|
|
20
20
|
/**
|
|
21
21
|
* Login
|
|
22
22
|
*/
|
|
23
|
-
export declare const login: (formData: any
|
|
23
|
+
export declare const login: (formData: any) => (dispatch: AppDispatch, getState: any, storage: AuthStorage) => Promise<void>;
|
|
24
24
|
/**
|
|
25
25
|
* Signup
|
|
26
26
|
*/
|
|
@@ -40,7 +40,7 @@ export declare const reset_password_confirm: (formData: any) => (dispatch: AppDi
|
|
|
40
40
|
/**
|
|
41
41
|
* Logout
|
|
42
42
|
*/
|
|
43
|
-
export declare const logout: (
|
|
43
|
+
export declare const logout: () => (dispatch: AppDispatch, getState: any, storage: AuthStorage) => Promise<void>;
|
|
44
44
|
/**
|
|
45
45
|
* Clear Errors
|
|
46
46
|
*/
|
|
@@ -48,10 +48,10 @@ export declare const clearErrors: () => (dispatch: AppDispatch) => void;
|
|
|
48
48
|
/**
|
|
49
49
|
* Change Password (Authenticated)
|
|
50
50
|
*/
|
|
51
|
-
export declare const changeLoggedInUserPassword: (formData: any
|
|
51
|
+
export declare const changeLoggedInUserPassword: (formData: any) => (dispatch: AppDispatch, getState: any, storage: AuthStorage) => Promise<{
|
|
52
52
|
type: string;
|
|
53
53
|
} | undefined>;
|
|
54
54
|
/**
|
|
55
55
|
* 🔄 Refresh Access Token
|
|
56
56
|
*/
|
|
57
|
-
export declare const refreshAccessToken: (
|
|
57
|
+
export declare const refreshAccessToken: () => (dispatch: AppDispatch, getState: any, storage: AuthStorage) => Promise<any>;
|
|
@@ -61,8 +61,8 @@ var getAuthConfig = function (storage) { return __awaiter(void 0, void 0, void 0
|
|
|
61
61
|
/**
|
|
62
62
|
* Load Authenticated User
|
|
63
63
|
*/
|
|
64
|
-
export var load_user = function (
|
|
65
|
-
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
64
|
+
export var load_user = function () {
|
|
65
|
+
return function (dispatch, getState, storage) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
66
|
var config, res, _a;
|
|
67
67
|
return __generator(this, function (_b) {
|
|
68
68
|
switch (_b.label) {
|
|
@@ -95,7 +95,7 @@ export var load_user = function (storage) {
|
|
|
95
95
|
/**
|
|
96
96
|
* Facebook Auth
|
|
97
97
|
*/
|
|
98
|
-
export var facebookAuthenticate = function (state, code
|
|
98
|
+
export var facebookAuthenticate = function (state, code) { return function (dispatch, getState, storage) { return __awaiter(void 0, void 0, void 0, function () {
|
|
99
99
|
var token, res, _a, access, refresh, err_1;
|
|
100
100
|
var _b;
|
|
101
101
|
return __generator(this, function (_c) {
|
|
@@ -122,7 +122,7 @@ export var facebookAuthenticate = function (state, code, storage) { return funct
|
|
|
122
122
|
type: FACEBOOK_AUTH_SUCCESS,
|
|
123
123
|
payload: res.data
|
|
124
124
|
});
|
|
125
|
-
dispatch(load_user(
|
|
125
|
+
dispatch(load_user());
|
|
126
126
|
return [3 /*break*/, 6];
|
|
127
127
|
case 5:
|
|
128
128
|
err_1 = _c.sent();
|
|
@@ -138,8 +138,8 @@ export var facebookAuthenticate = function (state, code, storage) { return funct
|
|
|
138
138
|
/**
|
|
139
139
|
* Check Authentication
|
|
140
140
|
*/
|
|
141
|
-
export var checkAuthenticated = function (
|
|
142
|
-
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
141
|
+
export var checkAuthenticated = function () {
|
|
142
|
+
return function (dispatch, getState, storage) { return __awaiter(void 0, void 0, void 0, function () {
|
|
143
143
|
var token, res, _a;
|
|
144
144
|
return __generator(this, function (_b) {
|
|
145
145
|
switch (_b.label) {
|
|
@@ -173,7 +173,7 @@ export var checkAuthenticated = function (storage) {
|
|
|
173
173
|
/**
|
|
174
174
|
* Login
|
|
175
175
|
*/
|
|
176
|
-
export var login = function (formData
|
|
176
|
+
export var login = function (formData) { return function (dispatch, getState, storage) { return __awaiter(void 0, void 0, void 0, function () {
|
|
177
177
|
var res, _a, access, refresh, err_2;
|
|
178
178
|
var _b;
|
|
179
179
|
return __generator(this, function (_c) {
|
|
@@ -195,7 +195,7 @@ export var login = function (formData, storage) { return function (dispatch) { r
|
|
|
195
195
|
status: res.status
|
|
196
196
|
}
|
|
197
197
|
});
|
|
198
|
-
dispatch(load_user(
|
|
198
|
+
dispatch(load_user());
|
|
199
199
|
return [3 /*break*/, 4];
|
|
200
200
|
case 3:
|
|
201
201
|
err_2 = _c.sent();
|
|
@@ -339,8 +339,8 @@ export var reset_password_confirm = function (formData) {
|
|
|
339
339
|
/**
|
|
340
340
|
* Logout
|
|
341
341
|
*/
|
|
342
|
-
export var logout = function (
|
|
343
|
-
return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
342
|
+
export var logout = function () {
|
|
343
|
+
return function (dispatch, getState, storage) { return __awaiter(void 0, void 0, void 0, function () {
|
|
344
344
|
return __generator(this, function (_a) {
|
|
345
345
|
switch (_a.label) {
|
|
346
346
|
case 0: return [4 /*yield*/, storage.clearTokens()];
|
|
@@ -361,7 +361,7 @@ export var clearErrors = function () { return function (dispatch) {
|
|
|
361
361
|
/**
|
|
362
362
|
* Change Password (Authenticated)
|
|
363
363
|
*/
|
|
364
|
-
export var changeLoggedInUserPassword = function (formData
|
|
364
|
+
export var changeLoggedInUserPassword = function (formData) { return function (dispatch, getState, storage) { return __awaiter(void 0, void 0, void 0, function () {
|
|
365
365
|
var config, res, err_7;
|
|
366
366
|
var _a;
|
|
367
367
|
return __generator(this, function (_b) {
|
|
@@ -397,7 +397,7 @@ export var changeLoggedInUserPassword = function (formData, storage) { return fu
|
|
|
397
397
|
/**
|
|
398
398
|
* 🔄 Refresh Access Token
|
|
399
399
|
*/
|
|
400
|
-
export var refreshAccessToken = function (
|
|
400
|
+
export var refreshAccessToken = function () { return function (dispatch, getState, storage) { return __awaiter(void 0, void 0, void 0, function () {
|
|
401
401
|
var refresh, res, access, err_8;
|
|
402
402
|
var _a;
|
|
403
403
|
return __generator(this, function (_b) {
|
|
@@ -432,7 +432,7 @@ export var refreshAccessToken = function (storage) { return function (dispatch)
|
|
|
432
432
|
}
|
|
433
433
|
});
|
|
434
434
|
// 🔄 Reload user after refresh
|
|
435
|
-
dispatch(load_user(
|
|
435
|
+
dispatch(load_user());
|
|
436
436
|
return [2 /*return*/, access];
|
|
437
437
|
case 6:
|
|
438
438
|
err_8 = _b.sent();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AuthStorage } from "../actions/types";
|
|
2
1
|
interface FormData {
|
|
3
2
|
current_password?: string;
|
|
4
3
|
new_password?: string;
|
|
@@ -12,5 +11,5 @@ interface ChangePasswordHookReturn {
|
|
|
12
11
|
onSubmit: (e: React.FormEvent) => Promise<void>;
|
|
13
12
|
status: any;
|
|
14
13
|
}
|
|
15
|
-
declare const useChangeAuthenticatedUserPassword: (initialFields: FormData
|
|
14
|
+
declare const useChangeAuthenticatedUserPassword: (initialFields: FormData) => ChangePasswordHookReturn;
|
|
16
15
|
export default useChangeAuthenticatedUserPassword;
|
|
@@ -49,7 +49,7 @@ import { useState, useCallback, useEffect } from "react";
|
|
|
49
49
|
import { useDispatch, useSelector } from "react-redux";
|
|
50
50
|
import { changeLoggedInUserPassword, clearErrors, } from "../actions/authActions";
|
|
51
51
|
// The custom hook is now typed with its parameters and return value
|
|
52
|
-
var useChangeAuthenticatedUserPassword = function (initialFields
|
|
52
|
+
var useChangeAuthenticatedUserPassword = function (initialFields) {
|
|
53
53
|
// useDispatch is typed with our custom AppDispatch
|
|
54
54
|
var dispatch = useDispatch();
|
|
55
55
|
// useState is typed as boolean, FormData, and string | null
|
|
@@ -93,7 +93,11 @@ var useChangeAuthenticatedUserPassword = function (initialFields, storage) {
|
|
|
93
93
|
case 1:
|
|
94
94
|
_a.trys.push([1, 3, 4, 5]);
|
|
95
95
|
// The dispatch call is type-safe
|
|
96
|
-
return [4 /*yield*/, dispatch(changeLoggedInUserPassword({
|
|
96
|
+
return [4 /*yield*/, dispatch(changeLoggedInUserPassword({
|
|
97
|
+
current_password: current_password,
|
|
98
|
+
new_password: new_password,
|
|
99
|
+
re_new_password: re_new_password,
|
|
100
|
+
}))];
|
|
97
101
|
case 2:
|
|
98
102
|
// The dispatch call is type-safe
|
|
99
103
|
_a.sent();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AuthStorage } from "../actions/types";
|
|
2
1
|
interface FacebookAuthHookReturn {
|
|
3
2
|
continueWithFacebook: () => Promise<void>;
|
|
4
3
|
authenticateWithFacebook: (state: string, code: string) => Promise<void>;
|
|
@@ -7,5 +6,5 @@ interface FacebookAuthHookReturn {
|
|
|
7
6
|
isStatus201: boolean;
|
|
8
7
|
loading: boolean;
|
|
9
8
|
}
|
|
10
|
-
declare const useFacebookAuth: (
|
|
9
|
+
declare const useFacebookAuth: () => FacebookAuthHookReturn;
|
|
11
10
|
export default useFacebookAuth;
|
|
@@ -40,7 +40,7 @@ import { facebookAuthenticate, clearErrors } from "../actions/authActions";
|
|
|
40
40
|
import axios from "axios";
|
|
41
41
|
import { getBaseURL } from "../apis/config";
|
|
42
42
|
// The custom hook is now typed with its parameters and return value
|
|
43
|
-
var useFacebookAuth = function (
|
|
43
|
+
var useFacebookAuth = function () {
|
|
44
44
|
// useDispatch is typed with our custom AppDispatch
|
|
45
45
|
var dispatch = useDispatch();
|
|
46
46
|
// useSelector is typed with AuthState for type-safe state access
|
|
@@ -77,7 +77,7 @@ var useFacebookAuth = function (storage) {
|
|
|
77
77
|
case 5: return [2 /*return*/];
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
|
-
}); }, [dispatch
|
|
80
|
+
}); }, [dispatch]);
|
|
81
81
|
// Authenticate with Facebook after redirection
|
|
82
82
|
var authenticateWithFacebook = useCallback(function (state, code) { return __awaiter(void 0, void 0, void 0, function () {
|
|
83
83
|
var err_2;
|
|
@@ -90,7 +90,7 @@ var useFacebookAuth = function (storage) {
|
|
|
90
90
|
_a.label = 1;
|
|
91
91
|
case 1:
|
|
92
92
|
_a.trys.push([1, 3, 4, 5]);
|
|
93
|
-
return [4 /*yield*/, dispatch(facebookAuthenticate(state, code
|
|
93
|
+
return [4 /*yield*/, dispatch(facebookAuthenticate(state, code))];
|
|
94
94
|
case 2:
|
|
95
95
|
_a.sent();
|
|
96
96
|
return [3 /*break*/, 5];
|
|
@@ -104,7 +104,7 @@ var useFacebookAuth = function (storage) {
|
|
|
104
104
|
case 5: return [2 /*return*/];
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
|
-
}); }, [dispatch
|
|
107
|
+
}); }, [dispatch]);
|
|
108
108
|
// Clear errors when the hook is unmounted
|
|
109
109
|
useEffect(function () {
|
|
110
110
|
// Clear errors when the component mounts
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AuthStorage } from "../actions/types";
|
|
2
1
|
interface AuthHookReturn {
|
|
3
2
|
error: any;
|
|
4
3
|
isAuthenticated: boolean | null;
|
|
@@ -8,5 +7,5 @@ interface AuthHookReturn {
|
|
|
8
7
|
refreshAuth: () => Promise<void>;
|
|
9
8
|
isLoading: boolean;
|
|
10
9
|
}
|
|
11
|
-
declare const useAuthicatedUser: (location: any
|
|
10
|
+
declare const useAuthicatedUser: (location: any) => AuthHookReturn;
|
|
12
11
|
export default useAuthicatedUser;
|
|
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
import { useCallback, useEffect, useState } from "react";
|
|
38
38
|
import { useDispatch, useSelector } from "react-redux";
|
|
39
39
|
import { checkAuthenticated, load_user, clearErrors, } from "../actions/authActions";
|
|
40
|
-
var useAuthicatedUser = function (location
|
|
40
|
+
var useAuthicatedUser = function (location) {
|
|
41
41
|
var dispatch = useDispatch();
|
|
42
42
|
// Use separate loading states for each async action
|
|
43
43
|
var _a = useState(true), isAuthLoading = _a[0], setIsAuthLoading = _a[1];
|
|
@@ -51,8 +51,10 @@ var useAuthicatedUser = function (location, storage) {
|
|
|
51
51
|
return __generator(this, function (_a) {
|
|
52
52
|
switch (_a.label) {
|
|
53
53
|
case 0:
|
|
54
|
+
if (isAuthenticated)
|
|
55
|
+
return [2 /*return*/];
|
|
54
56
|
setIsAuthLoading(true);
|
|
55
|
-
return [4 /*yield*/, dispatch(checkAuthenticated(
|
|
57
|
+
return [4 /*yield*/, dispatch(checkAuthenticated())];
|
|
56
58
|
case 1:
|
|
57
59
|
_a.sent();
|
|
58
60
|
setIsAuthLoading(false);
|
|
@@ -61,7 +63,7 @@ var useAuthicatedUser = function (location, storage) {
|
|
|
61
63
|
});
|
|
62
64
|
}); };
|
|
63
65
|
runAuthCheck();
|
|
64
|
-
}, [dispatch, location
|
|
66
|
+
}, [dispatch, location]);
|
|
65
67
|
// 2️⃣ Whenever isAuthenticated flips true: load the user profile
|
|
66
68
|
useEffect(function () {
|
|
67
69
|
if (isAuthenticated) {
|
|
@@ -70,7 +72,7 @@ var useAuthicatedUser = function (location, storage) {
|
|
|
70
72
|
switch (_a.label) {
|
|
71
73
|
case 0:
|
|
72
74
|
setIsUserLoading(true);
|
|
73
|
-
return [4 /*yield*/, dispatch(load_user(
|
|
75
|
+
return [4 /*yield*/, dispatch(load_user())];
|
|
74
76
|
case 1:
|
|
75
77
|
_a.sent();
|
|
76
78
|
setIsUserLoading(false);
|
|
@@ -80,23 +82,23 @@ var useAuthicatedUser = function (location, storage) {
|
|
|
80
82
|
}); };
|
|
81
83
|
runUserLoad();
|
|
82
84
|
}
|
|
83
|
-
}, [dispatch, isAuthenticated
|
|
85
|
+
}, [dispatch, isAuthenticated]);
|
|
84
86
|
// Expose a manual “refresh user” function
|
|
85
87
|
var refreshUser = useCallback(function () {
|
|
86
|
-
dispatch(load_user(
|
|
87
|
-
}, [dispatch
|
|
88
|
+
dispatch(load_user());
|
|
89
|
+
}, [dispatch]);
|
|
88
90
|
// Expose a manual “re-auth + reload” function
|
|
89
91
|
var refreshAuth = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
92
|
return __generator(this, function (_a) {
|
|
91
93
|
switch (_a.label) {
|
|
92
|
-
case 0: return [4 /*yield*/, dispatch(checkAuthenticated(
|
|
94
|
+
case 0: return [4 /*yield*/, dispatch(checkAuthenticated())];
|
|
93
95
|
case 1:
|
|
94
96
|
_a.sent();
|
|
95
|
-
dispatch(load_user(
|
|
97
|
+
dispatch(load_user());
|
|
96
98
|
return [2 /*return*/];
|
|
97
99
|
}
|
|
98
100
|
});
|
|
99
|
-
}); }, [dispatch
|
|
101
|
+
}); }, [dispatch]);
|
|
100
102
|
// Wrap clearErrors so consumer can wipe errors
|
|
101
103
|
var clearErrorsWrapper = useCallback(function () {
|
|
102
104
|
dispatch(clearErrors());
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AuthStorage } from "../actions/types";
|
|
2
1
|
interface LoginHookReturn {
|
|
3
2
|
loading: boolean;
|
|
4
3
|
formData: any;
|
|
@@ -9,5 +8,5 @@ interface LoginHookReturn {
|
|
|
9
8
|
isAuthenticated: boolean | null;
|
|
10
9
|
isStatus200: boolean;
|
|
11
10
|
}
|
|
12
|
-
declare const useLogin: (initialFields: any, location: any
|
|
11
|
+
declare const useLogin: (initialFields: any, location: any) => LoginHookReturn;
|
|
13
12
|
export default useLogin;
|
|
@@ -49,7 +49,7 @@ import { useState, useCallback, useEffect } from "react";
|
|
|
49
49
|
import { useDispatch, useSelector } from "react-redux";
|
|
50
50
|
import { login, clearErrors } from "../actions/authActions";
|
|
51
51
|
// The custom hook is now typed with its parameters and return value
|
|
52
|
-
var useLogin = function (initialFields, location
|
|
52
|
+
var useLogin = function (initialFields, location) {
|
|
53
53
|
var _a = useState(false), loading = _a[0], setLoading = _a[1];
|
|
54
54
|
var _b = useState(initialFields), formData = _b[0], setFormData = _b[1];
|
|
55
55
|
// useDispatch is typed with our custom AppDispatch
|
|
@@ -88,7 +88,7 @@ var useLogin = function (initialFields, location, storage) {
|
|
|
88
88
|
case 1:
|
|
89
89
|
_a.trys.push([1, 3, 4, 5]);
|
|
90
90
|
// The dispatch call is type-safe
|
|
91
|
-
return [4 /*yield*/, dispatch(login(formData
|
|
91
|
+
return [4 /*yield*/, dispatch(login(formData))];
|
|
92
92
|
case 2:
|
|
93
93
|
// The dispatch call is type-safe
|
|
94
94
|
_a.sent();
|
|
@@ -104,7 +104,7 @@ var useLogin = function (initialFields, location, storage) {
|
|
|
104
104
|
case 5: return [2 /*return*/];
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
|
-
}); }, [dispatch, formData
|
|
107
|
+
}); }, [dispatch, formData]);
|
|
108
108
|
return {
|
|
109
109
|
loading: loading,
|
|
110
110
|
formData: formData,
|
|
@@ -2,12 +2,12 @@ import { useCallback } from "react";
|
|
|
2
2
|
import { useDispatch } from "react-redux";
|
|
3
3
|
import { logout } from "../actions/authActions";
|
|
4
4
|
// The custom hook is now typed with its return value
|
|
5
|
-
var useLogout = function (
|
|
5
|
+
var useLogout = function () {
|
|
6
6
|
// useDispatch is typed with our custom AppDispatch
|
|
7
7
|
var dispatch = useDispatch();
|
|
8
8
|
// The handleLogout function is memoized and typed
|
|
9
9
|
var handleLogout = useCallback(function () {
|
|
10
|
-
dispatch(logout(
|
|
10
|
+
dispatch(logout());
|
|
11
11
|
}, [dispatch]);
|
|
12
12
|
return handleLogout;
|
|
13
13
|
};
|
|
@@ -66,7 +66,7 @@ var useBiometricAuth = function (_a) {
|
|
|
66
66
|
access = _a.sent();
|
|
67
67
|
if (access)
|
|
68
68
|
return [2 /*return*/, access];
|
|
69
|
-
return [4 /*yield*/, dispatch(refreshAccessToken(
|
|
69
|
+
return [4 /*yield*/, dispatch(refreshAccessToken())];
|
|
70
70
|
case 5:
|
|
71
71
|
newAccess = _a.sent();
|
|
72
72
|
if (!newAccess)
|
|
@@ -36,7 +36,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
import * as Keychain from 'react-native-keychain';
|
|
38
38
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
39
|
+
import { Platform } from 'react-native';
|
|
39
40
|
var ACCESS_KEY = 'access';
|
|
41
|
+
var REFRESH_KEY = 'refresh'; // Fallback for web
|
|
40
42
|
export var storage = {
|
|
41
43
|
/**
|
|
42
44
|
* 🔑 Access token (fast access)
|
|
@@ -56,16 +58,14 @@ export var storage = {
|
|
|
56
58
|
var credentials;
|
|
57
59
|
return __generator(this, function (_a) {
|
|
58
60
|
switch (_a.label) {
|
|
59
|
-
case 0:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
case
|
|
61
|
+
case 0:
|
|
62
|
+
if (!(Platform.OS === 'web')) return [3 /*break*/, 2];
|
|
63
|
+
return [4 /*yield*/, AsyncStorage.getItem(REFRESH_KEY)];
|
|
64
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
65
|
+
case 2: return [4 /*yield*/, Keychain.getGenericPassword()];
|
|
66
|
+
case 3:
|
|
65
67
|
credentials = _a.sent();
|
|
66
|
-
|
|
67
|
-
return [2 /*return*/, null];
|
|
68
|
-
return [2 /*return*/, credentials.password]; // refresh token
|
|
68
|
+
return [2 /*return*/, credentials ? credentials.password : null];
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
}); },
|
|
@@ -78,17 +78,25 @@ export var storage = {
|
|
|
78
78
|
case 0: return [4 /*yield*/, AsyncStorage.setItem(ACCESS_KEY, access)];
|
|
79
79
|
case 1:
|
|
80
80
|
_a.sent();
|
|
81
|
-
if (!refresh) return [3 /*break*/,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
accessible: Keychain.ACCESSIBLE.WHEN_UNLOCKED,
|
|
86
|
-
// authenticationType: Keychain.AUTHENTICATION_TYPE.BIOMETRICS,
|
|
87
|
-
})];
|
|
81
|
+
if (!refresh) return [3 /*break*/, 5];
|
|
82
|
+
if (!(Platform.OS === 'web')) return [3 /*break*/, 3];
|
|
83
|
+
// Use localStorage or AsyncStorage for web fallback
|
|
84
|
+
return [4 /*yield*/, AsyncStorage.setItem(REFRESH_KEY, refresh)];
|
|
88
85
|
case 2:
|
|
86
|
+
// Use localStorage or AsyncStorage for web fallback
|
|
89
87
|
_a.sent();
|
|
90
|
-
|
|
91
|
-
case 3:
|
|
88
|
+
return [3 /*break*/, 5];
|
|
89
|
+
case 3:
|
|
90
|
+
// Native Keychain logic
|
|
91
|
+
return [4 /*yield*/, Keychain.setGenericPassword('refreshToken', refresh, {
|
|
92
|
+
accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE,
|
|
93
|
+
accessible: Keychain.ACCESSIBLE.WHEN_UNLOCKED,
|
|
94
|
+
})];
|
|
95
|
+
case 4:
|
|
96
|
+
// Native Keychain logic
|
|
97
|
+
_a.sent();
|
|
98
|
+
_a.label = 5;
|
|
99
|
+
case 5: return [2 /*return*/];
|
|
92
100
|
}
|
|
93
101
|
});
|
|
94
102
|
}); },
|
|
@@ -101,10 +109,16 @@ export var storage = {
|
|
|
101
109
|
case 0: return [4 /*yield*/, AsyncStorage.removeItem(ACCESS_KEY)];
|
|
102
110
|
case 1:
|
|
103
111
|
_a.sent();
|
|
104
|
-
return [
|
|
112
|
+
if (!(Platform.OS === 'web')) return [3 /*break*/, 3];
|
|
113
|
+
return [4 /*yield*/, AsyncStorage.removeItem(REFRESH_KEY)];
|
|
105
114
|
case 2:
|
|
106
115
|
_a.sent();
|
|
107
|
-
return [
|
|
116
|
+
return [3 /*break*/, 5];
|
|
117
|
+
case 3: return [4 /*yield*/, Keychain.resetGenericPassword()];
|
|
118
|
+
case 4:
|
|
119
|
+
_a.sent();
|
|
120
|
+
_a.label = 5;
|
|
121
|
+
case 5: return [2 /*return*/];
|
|
108
122
|
}
|
|
109
123
|
});
|
|
110
124
|
}); },
|
|
@@ -3,6 +3,12 @@ declare const store: import("@reduxjs/toolkit").EnhancedStore<{
|
|
|
3
3
|
}, any, import("@reduxjs/toolkit").Tuple<[import("redux").StoreEnhancer<{
|
|
4
4
|
dispatch: import("redux-thunk").ThunkDispatch<{
|
|
5
5
|
auth: import("../auth-core/reducers/authReducer").AuthState;
|
|
6
|
-
},
|
|
6
|
+
}, {
|
|
7
|
+
getAccessToken: () => Promise<string | null>;
|
|
8
|
+
getRefreshToken: () => Promise<string | null>;
|
|
9
|
+
setTokens: (access: string, refresh?: string) => Promise<void>;
|
|
10
|
+
clearTokens: () => Promise<void>;
|
|
11
|
+
}, import("redux").UnknownAction>;
|
|
7
12
|
}>, import("redux").StoreEnhancer]>>;
|
|
13
|
+
export type AppDispatch = typeof store.dispatch;
|
|
8
14
|
export default store;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { configureStore } from '@reduxjs/toolkit';
|
|
2
2
|
import rootReducer from '../auth-core/reducers';
|
|
3
|
+
import { storage } from './storage/nativeStorage';
|
|
3
4
|
var initialState = {};
|
|
4
5
|
var store = configureStore({
|
|
5
6
|
reducer: rootReducer,
|
|
6
|
-
// If you want to set an initial state, use preloadedState instead:
|
|
7
7
|
preloadedState: initialState,
|
|
8
|
+
// 2. This is the "Magic" part
|
|
9
|
+
middleware: function (getDefaultMiddleware) {
|
|
10
|
+
return getDefaultMiddleware({
|
|
11
|
+
thunk: {
|
|
12
|
+
extraArgument: storage, // 💉 Inject the "Fuel Tank" here
|
|
13
|
+
},
|
|
14
|
+
serializableCheck: false, // Recommended when passing storage objects
|
|
15
|
+
});
|
|
16
|
+
},
|
|
8
17
|
});
|
|
9
18
|
export default store;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AuthStorage } from "../../auth-core/actions/types";
|
|
2
1
|
interface GoogleAuthHookReturn {
|
|
3
2
|
continueWithGoogle: () => Promise<void>;
|
|
4
3
|
authenticateWithGoogle: (state: string, code: string) => Promise<void>;
|
|
@@ -7,5 +6,5 @@ interface GoogleAuthHookReturn {
|
|
|
7
6
|
isStatus201: boolean;
|
|
8
7
|
loading: boolean;
|
|
9
8
|
}
|
|
10
|
-
declare const useGoogleAuth: (
|
|
9
|
+
declare const useGoogleAuth: () => GoogleAuthHookReturn;
|
|
11
10
|
export default useGoogleAuth;
|
|
@@ -41,7 +41,7 @@ import axios from "axios";
|
|
|
41
41
|
import { googleAuthenticate } from "../oauth/google";
|
|
42
42
|
import { getBaseURL } from "../../auth-core/apis/config";
|
|
43
43
|
// The custom hook is now typed with its parameters and return value
|
|
44
|
-
var useGoogleAuth = function (
|
|
44
|
+
var useGoogleAuth = function () {
|
|
45
45
|
// useDispatch is typed with our custom AppDispatch
|
|
46
46
|
var dispatch = useDispatch();
|
|
47
47
|
// useSelector is typed with AuthState for type-safe state access
|
|
@@ -91,7 +91,7 @@ var useGoogleAuth = function (storage) {
|
|
|
91
91
|
_a.label = 1;
|
|
92
92
|
case 1:
|
|
93
93
|
_a.trys.push([1, 3, 4, 5]);
|
|
94
|
-
return [4 /*yield*/, dispatch(googleAuthenticate(state, code
|
|
94
|
+
return [4 /*yield*/, dispatch(googleAuthenticate(state, code))];
|
|
95
95
|
case 2:
|
|
96
96
|
_a.sent();
|
|
97
97
|
return [3 /*break*/, 5];
|
|
@@ -105,7 +105,7 @@ var useGoogleAuth = function (storage) {
|
|
|
105
105
|
case 5: return [2 /*return*/];
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
|
-
}); }, [dispatch
|
|
108
|
+
}); }, [dispatch]);
|
|
109
109
|
// Clear errors when the hook is unmounted
|
|
110
110
|
useEffect(function () {
|
|
111
111
|
// Clear errors when the component mounts
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AppDispatch } from '../../auth-core/actions/authActions';
|
|
2
2
|
import { AuthStorage } from '../../auth-core/actions/types';
|
|
3
|
-
export declare const googleAuthenticate: (state: any, code: any
|
|
3
|
+
export declare const googleAuthenticate: (state: any, code: any) => (dispatch: AppDispatch, getState: any, storage: AuthStorage) => Promise<void>;
|
|
@@ -49,7 +49,7 @@ import axios from 'axios';
|
|
|
49
49
|
import { load_user } from '../../auth-core/actions/authActions';
|
|
50
50
|
import { GOOGLE_AUTH_FAIL, GOOGLE_AUTH_SUCCESS, } from '../../auth-core/actions/types';
|
|
51
51
|
import { getBaseURL } from '../../auth-core/apis/config';
|
|
52
|
-
export var googleAuthenticate = function (state, code
|
|
52
|
+
export var googleAuthenticate = function (state, code) { return function (dispatch, getState, storage) { return __awaiter(void 0, void 0, void 0, function () {
|
|
53
53
|
var config, details_1, formBody, res, err_1, error;
|
|
54
54
|
return __generator(this, function (_a) {
|
|
55
55
|
switch (_a.label) {
|
|
@@ -75,7 +75,7 @@ export var googleAuthenticate = function (state, code, storage) { return functio
|
|
|
75
75
|
type: GOOGLE_AUTH_SUCCESS,
|
|
76
76
|
payload: __assign(__assign({}, res.data), { status: res.status })
|
|
77
77
|
});
|
|
78
|
-
dispatch(load_user(
|
|
78
|
+
dispatch(load_user());
|
|
79
79
|
return [3 /*break*/, 4];
|
|
80
80
|
case 3:
|
|
81
81
|
err_1 = _a.sent();
|
package/dist/auth-web/store.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ declare const store: import("@reduxjs/toolkit").EnhancedStore<{
|
|
|
3
3
|
}, any, import("@reduxjs/toolkit").Tuple<[import("redux").StoreEnhancer<{
|
|
4
4
|
dispatch: import("redux-thunk").ThunkDispatch<{
|
|
5
5
|
auth: import("../auth-core/reducers/authReducer").AuthState;
|
|
6
|
-
},
|
|
6
|
+
}, {
|
|
7
|
+
getAccessToken: () => string | null;
|
|
8
|
+
setTokens: (access: string, refresh?: string) => void;
|
|
9
|
+
clearTokens: () => void;
|
|
10
|
+
}, import("redux").UnknownAction>;
|
|
7
11
|
}>, import("redux").StoreEnhancer]>>;
|
|
12
|
+
export type AppDispatch = typeof store.dispatch;
|
|
8
13
|
export default store;
|
package/dist/auth-web/store.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { configureStore } from '@reduxjs/toolkit';
|
|
2
2
|
import rootReducer from '../auth-core/reducers';
|
|
3
|
+
import { storage } from './storage/webStorage';
|
|
3
4
|
var initialState = {};
|
|
4
5
|
var store = configureStore({
|
|
5
6
|
reducer: rootReducer,
|
|
6
|
-
// If you want to set an initial state, use preloadedState instead:
|
|
7
7
|
preloadedState: initialState,
|
|
8
|
+
// 2. This is the "Magic" part
|
|
9
|
+
middleware: function (getDefaultMiddleware) {
|
|
10
|
+
return getDefaultMiddleware({
|
|
11
|
+
thunk: {
|
|
12
|
+
extraArgument: storage, // 💉 Inject the "Fuel Tank" here
|
|
13
|
+
},
|
|
14
|
+
serializableCheck: false, // Recommended when passing storage objects
|
|
15
|
+
});
|
|
16
|
+
},
|
|
8
17
|
});
|
|
9
18
|
export default store;
|