dauth-context-react 0.1.998 → 0.1.999
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/dauth-context-react.cjs.development.js +32 -91
- package/dist/dauth-context-react.cjs.development.js.map +1 -1
- package/dist/dauth-context-react.cjs.production.min.js +1 -1
- package/dist/dauth-context-react.cjs.production.min.js.map +1 -1
- package/dist/dauth-context-react.esm.js +32 -91
- package/dist/dauth-context-react.esm.js.map +1 -1
- package/dist/reducer/dauth.actions.d.ts +3 -2
- package/package.json +1 -1
- package/src/api/dauth.api.ts +2 -2
- package/src/index.tsx +3 -23
- package/src/reducer/dauth.actions.ts +14 -73
package/package.json
CHANGED
package/src/api/dauth.api.ts
CHANGED
|
@@ -8,7 +8,7 @@ export const getUserAPI = async (
|
|
|
8
8
|
const params = {
|
|
9
9
|
method: 'GET',
|
|
10
10
|
headers: {
|
|
11
|
-
Authorization:
|
|
11
|
+
Authorization: token,
|
|
12
12
|
'Content-Type': 'application/json',
|
|
13
13
|
},
|
|
14
14
|
};
|
|
@@ -28,7 +28,7 @@ export const updateUserAPI = async (
|
|
|
28
28
|
const params = {
|
|
29
29
|
method: 'PATCH',
|
|
30
30
|
headers: {
|
|
31
|
-
Authorization:
|
|
31
|
+
Authorization: token,
|
|
32
32
|
'Content-Type': 'application/json',
|
|
33
33
|
},
|
|
34
34
|
body: JSON.stringify(user),
|
package/src/index.tsx
CHANGED
|
@@ -35,9 +35,9 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
|
|
|
35
35
|
const token_ls = localStorage.getItem(DAUTH_STATE);
|
|
36
36
|
if (!token_ls) return;
|
|
37
37
|
action.checkTokenAction({ dispatch, domainName, sid, token: token_ls });
|
|
38
|
-
}, 1000 * 60);
|
|
38
|
+
}, 1000 * 60 * 2);
|
|
39
39
|
return () => clearInterval(interval);
|
|
40
|
-
}, [
|
|
40
|
+
}, []);
|
|
41
41
|
|
|
42
42
|
// Catch login redirect
|
|
43
43
|
useEffect(() => {
|
|
@@ -54,7 +54,7 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
|
|
|
54
54
|
useEffect(() => {
|
|
55
55
|
const dauth_state_ls = localStorage.getItem(DAUTH_STATE);
|
|
56
56
|
if (dauth_state_ls && !dauthState.isAuthenticated) {
|
|
57
|
-
action.setAutoLoginAction({ dispatch, dauth_state_ls, domainName });
|
|
57
|
+
action.setAutoLoginAction({ dispatch, dauth_state_ls, domainName, sid });
|
|
58
58
|
}
|
|
59
59
|
}, []);
|
|
60
60
|
|
|
@@ -71,26 +71,6 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
|
|
|
71
71
|
const getAccessToken = useCallback(async () => {
|
|
72
72
|
const token = await action.getAccessTokenAction({ dispatch, domainName });
|
|
73
73
|
return token;
|
|
74
|
-
// const token_ls = localStorage.getItem(DAUTH_STATE);
|
|
75
|
-
// if (!token_ls) return;
|
|
76
|
-
// try {
|
|
77
|
-
// const refreshAccessTokenFetch = await refreshAccessTokenAPI(
|
|
78
|
-
// domainName,
|
|
79
|
-
// token_ls
|
|
80
|
-
// );
|
|
81
|
-
// if (refreshAccessTokenFetch.response.status === 200) {
|
|
82
|
-
// return refreshAccessTokenFetch.data.accessToken ?? token_ls;
|
|
83
|
-
// } else {
|
|
84
|
-
// action.resetUser(dispatch);
|
|
85
|
-
// window.location.replace(
|
|
86
|
-
// `${getClientBasePath({ domainName })}/t-sign/${sid}`
|
|
87
|
-
// );
|
|
88
|
-
// return 'token-not-found';
|
|
89
|
-
// }
|
|
90
|
-
// } catch (error) {
|
|
91
|
-
// action.resetUser(dispatch);
|
|
92
|
-
// throw error;
|
|
93
|
-
// }
|
|
94
74
|
}, []);
|
|
95
75
|
|
|
96
76
|
const updateUser = useCallback(
|
|
@@ -38,11 +38,11 @@ export async function setDauthStateAction({
|
|
|
38
38
|
);
|
|
39
39
|
return localStorage.setItem(DAUTH_STATE, dauth_state);
|
|
40
40
|
} else {
|
|
41
|
-
return
|
|
41
|
+
return resetUser(dispatch);
|
|
42
42
|
}
|
|
43
43
|
} catch (error) {
|
|
44
|
-
localStorage.removeItem(DAUTH_STATE);
|
|
45
44
|
console.log(error);
|
|
45
|
+
return resetUser(dispatch);
|
|
46
46
|
} finally {
|
|
47
47
|
dispatch({
|
|
48
48
|
type: DauthTypes.SET_IS_LOADING,
|
|
@@ -55,11 +55,13 @@ type TSetAutoLoginAction = {
|
|
|
55
55
|
dispatch: any;
|
|
56
56
|
dauth_state_ls: string;
|
|
57
57
|
domainName: string;
|
|
58
|
+
sid: string;
|
|
58
59
|
};
|
|
59
60
|
export async function setAutoLoginAction({
|
|
60
61
|
dispatch,
|
|
61
62
|
dauth_state_ls,
|
|
62
63
|
domainName,
|
|
64
|
+
sid,
|
|
63
65
|
}: TSetAutoLoginAction) {
|
|
64
66
|
dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });
|
|
65
67
|
try {
|
|
@@ -84,33 +86,20 @@ export async function setAutoLoginAction({
|
|
|
84
86
|
);
|
|
85
87
|
return;
|
|
86
88
|
} else {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// user: {} as IDauthUser,
|
|
92
|
-
// domain: {} as IDauthDomainState,
|
|
93
|
-
// isAuthenticated: false,
|
|
94
|
-
// },
|
|
95
|
-
// });
|
|
96
|
-
// localStorage.removeItem(DAUTH_STATE);
|
|
89
|
+
window.location.replace(
|
|
90
|
+
`${getClientBasePath({ domainName })}/t-sign/${sid}`
|
|
91
|
+
);
|
|
92
|
+
return resetUser(dispatch);
|
|
97
93
|
}
|
|
98
94
|
} else {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// user: {} as IDauthUser,
|
|
104
|
-
// domain: {} as IDauthDomainState,
|
|
105
|
-
// isAuthenticated: false,
|
|
106
|
-
// },
|
|
107
|
-
// });
|
|
108
|
-
// localStorage.removeItem(DAUTH_STATE);
|
|
95
|
+
window.location.replace(
|
|
96
|
+
`${getClientBasePath({ domainName })}/t-sign/${sid}`
|
|
97
|
+
);
|
|
98
|
+
return resetUser(dispatch);
|
|
109
99
|
}
|
|
110
100
|
} catch (error) {
|
|
111
|
-
resetUser(dispatch);
|
|
112
|
-
// localStorage.removeItem(DAUTH_STATE);
|
|
113
101
|
console.log(error);
|
|
102
|
+
return resetUser(dispatch);
|
|
114
103
|
} finally {
|
|
115
104
|
dispatch({
|
|
116
105
|
type: DauthTypes.SET_IS_LOADING,
|
|
@@ -167,7 +156,7 @@ export async function setUpdateUserAction({
|
|
|
167
156
|
payload: getUserFetch.data.user,
|
|
168
157
|
});
|
|
169
158
|
} else {
|
|
170
|
-
console.log('Update user error');
|
|
159
|
+
console.log('Update user error', getUserFetch.data.message);
|
|
171
160
|
return;
|
|
172
161
|
}
|
|
173
162
|
} catch (error) {
|
|
@@ -229,54 +218,6 @@ export async function sendEmailVerificationAction({
|
|
|
229
218
|
}
|
|
230
219
|
}
|
|
231
220
|
|
|
232
|
-
// export async function refreshTokenAction({
|
|
233
|
-
// dispatch,
|
|
234
|
-
// domainName,
|
|
235
|
-
// token,
|
|
236
|
-
// }: {
|
|
237
|
-
// dispatch: any;
|
|
238
|
-
// domainName: string;
|
|
239
|
-
// token: string;
|
|
240
|
-
// }) {
|
|
241
|
-
// try {
|
|
242
|
-
// const refreshAccessTokenFetch = await refreshAccessTokenAPI(
|
|
243
|
-
// domainName,
|
|
244
|
-
// token
|
|
245
|
-
// );
|
|
246
|
-
// if (refreshAccessTokenFetch.response.status === 200) {
|
|
247
|
-
// console.log(refreshAccessTokenFetch.data.accessToken);
|
|
248
|
-
// localStorage.removeItem(DAUTH_STATE);
|
|
249
|
-
// localStorage.setItem(
|
|
250
|
-
// DAUTH_STATE,
|
|
251
|
-
// refreshAccessTokenFetch.data.accessToken
|
|
252
|
-
// );
|
|
253
|
-
// return;
|
|
254
|
-
// } else {
|
|
255
|
-
// dispatch({
|
|
256
|
-
// type: DauthTypes.LOGIN,
|
|
257
|
-
// payload: {
|
|
258
|
-
// user: {} as IDauthUser,
|
|
259
|
-
// domain: {} as IDauthDomainState,
|
|
260
|
-
// isAuthenticated: false,
|
|
261
|
-
// },
|
|
262
|
-
// });
|
|
263
|
-
// localStorage.removeItem(DAUTH_STATE);
|
|
264
|
-
// return;
|
|
265
|
-
// }
|
|
266
|
-
// } catch (error) {
|
|
267
|
-
// dispatch({
|
|
268
|
-
// type: DauthTypes.LOGIN,
|
|
269
|
-
// payload: {
|
|
270
|
-
// user: {} as IDauthUser,
|
|
271
|
-
// domain: {} as IDauthDomainState,
|
|
272
|
-
// isAuthenticated: false,
|
|
273
|
-
// },
|
|
274
|
-
// });
|
|
275
|
-
// localStorage.removeItem(DAUTH_STATE);
|
|
276
|
-
// console.log(error);
|
|
277
|
-
// }
|
|
278
|
-
// }
|
|
279
|
-
|
|
280
221
|
export async function checkTokenAction({
|
|
281
222
|
dispatch,
|
|
282
223
|
domainName,
|