dauth-context-react 0.1.985 → 0.1.987

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.
@@ -27,14 +27,9 @@ declare type TSetSendEmailVerificationAction = {
27
27
  token: string;
28
28
  };
29
29
  export declare function sendEmailVerificationAction({ dispatch, domainName, token, }: TSetSendEmailVerificationAction): Promise<any>;
30
- export declare function refreshTokenAction({ dispatch, domainName, token, }: {
31
- dispatch: any;
32
- domainName: string;
33
- token: string;
34
- }): Promise<void>;
35
30
  export declare function checkTokenAction({ dispatch, domainName, token, }: {
36
31
  dispatch: any;
37
32
  domainName: string;
38
33
  token: string;
39
- }): Promise<void>;
34
+ }): Promise<any>;
40
35
  export {};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.985",
2
+ "version": "0.1.987",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
package/src/index.tsx CHANGED
@@ -35,15 +35,15 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
35
35
  // action.refreshTokenAction({ dispatch, domainName, token: token_ls });
36
36
  // }, [domainName]);
37
37
 
38
- // useEffect(() => {
39
- // const token_ls = localStorage.getItem(DAUTH_STATE);
40
- // let interval = setInterval(() => {
41
- // if (!token_ls) return;
42
- // action.checkTokenAction({ dispatch, domainName, token: token_ls });
43
- // }, 6000);
44
- // // }, 1000 * 60 * 5);
45
- // return () => clearInterval(interval);
46
- // }, [domainName]);
38
+ useEffect(() => {
39
+ const token_ls = localStorage.getItem(DAUTH_STATE);
40
+ let interval = setInterval(() => {
41
+ if (!token_ls) return;
42
+ action.checkTokenAction({ dispatch, domainName, token: token_ls });
43
+ }, 6000);
44
+ // }, 1000 * 60 * 5);
45
+ return () => clearInterval(interval);
46
+ }, [domainName]);
47
47
 
48
48
  // Catch login redirect
49
49
  useEffect(() => {
@@ -83,43 +83,32 @@ export async function setAutoLoginAction({
83
83
  );
84
84
  return;
85
85
  } else {
86
- dispatch({
87
- type: DauthTypes.LOGIN,
88
- payload: {
89
- user: {} as IDauthUser,
90
- domain: {} as IDauthDomainState,
91
- isAuthenticated: false,
92
- },
93
- });
94
- localStorage.removeItem(DAUTH_STATE);
86
+ resetUser(dispatch);
87
+ // dispatch({
88
+ // type: DauthTypes.LOGIN,
89
+ // payload: {
90
+ // user: {} as IDauthUser,
91
+ // domain: {} as IDauthDomainState,
92
+ // isAuthenticated: false,
93
+ // },
94
+ // });
95
+ // localStorage.removeItem(DAUTH_STATE);
95
96
  }
96
97
  } else {
97
- dispatch({
98
- type: DauthTypes.LOGIN,
99
- payload: {
100
- user: {} as IDauthUser,
101
- domain: {} as IDauthDomainState,
102
- isAuthenticated: false,
103
- },
104
- });
105
- localStorage.removeItem(DAUTH_STATE);
98
+ resetUser(dispatch);
99
+ // dispatch({
100
+ // type: DauthTypes.LOGIN,
101
+ // payload: {
102
+ // user: {} as IDauthUser,
103
+ // domain: {} as IDauthDomainState,
104
+ // isAuthenticated: false,
105
+ // },
106
+ // });
107
+ // localStorage.removeItem(DAUTH_STATE);
106
108
  }
107
- // const getUserFetch = await getUserAPI(domainName, dauth_state_ls);
108
- // if (getUserFetch.response.status === 200) {
109
- // dispatch({
110
- // type: DauthTypes.LOGIN,
111
- // payload: {
112
- // user: getUserFetch.data.user,
113
- // domain: getUserFetch.data.domain,
114
- // isAuthenticated: true,
115
- // },
116
- // });
117
- // localStorage.setItem(DAUTH_STATE, dauth_state_ls);
118
- // } else {
119
- // localStorage.removeItem(DAUTH_STATE);
120
- // }
121
109
  } catch (error) {
122
- localStorage.removeItem(DAUTH_STATE);
110
+ resetUser(dispatch);
111
+ // localStorage.removeItem(DAUTH_STATE);
123
112
  console.log(error);
124
113
  } finally {
125
114
  dispatch({
@@ -239,53 +228,53 @@ export async function sendEmailVerificationAction({
239
228
  }
240
229
  }
241
230
 
242
- export async function refreshTokenAction({
243
- dispatch,
244
- domainName,
245
- token,
246
- }: {
247
- dispatch: any;
248
- domainName: string;
249
- token: string;
250
- }) {
251
- try {
252
- const refreshAccessTokenFetch = await refreshAccessTokenAPI(
253
- domainName,
254
- token
255
- );
256
- if (refreshAccessTokenFetch.response.status === 200) {
257
- console.log(refreshAccessTokenFetch.data.accessToken);
258
- localStorage.removeItem(DAUTH_STATE);
259
- localStorage.setItem(
260
- DAUTH_STATE,
261
- refreshAccessTokenFetch.data.accessToken
262
- );
263
- return;
264
- } else {
265
- dispatch({
266
- type: DauthTypes.LOGIN,
267
- payload: {
268
- user: {} as IDauthUser,
269
- domain: {} as IDauthDomainState,
270
- isAuthenticated: false,
271
- },
272
- });
273
- localStorage.removeItem(DAUTH_STATE);
274
- return;
275
- }
276
- } catch (error) {
277
- dispatch({
278
- type: DauthTypes.LOGIN,
279
- payload: {
280
- user: {} as IDauthUser,
281
- domain: {} as IDauthDomainState,
282
- isAuthenticated: false,
283
- },
284
- });
285
- localStorage.removeItem(DAUTH_STATE);
286
- console.log(error);
287
- }
288
- }
231
+ // export async function refreshTokenAction({
232
+ // dispatch,
233
+ // domainName,
234
+ // token,
235
+ // }: {
236
+ // dispatch: any;
237
+ // domainName: string;
238
+ // token: string;
239
+ // }) {
240
+ // try {
241
+ // const refreshAccessTokenFetch = await refreshAccessTokenAPI(
242
+ // domainName,
243
+ // token
244
+ // );
245
+ // if (refreshAccessTokenFetch.response.status === 200) {
246
+ // console.log(refreshAccessTokenFetch.data.accessToken);
247
+ // localStorage.removeItem(DAUTH_STATE);
248
+ // localStorage.setItem(
249
+ // DAUTH_STATE,
250
+ // refreshAccessTokenFetch.data.accessToken
251
+ // );
252
+ // return;
253
+ // } else {
254
+ // dispatch({
255
+ // type: DauthTypes.LOGIN,
256
+ // payload: {
257
+ // user: {} as IDauthUser,
258
+ // domain: {} as IDauthDomainState,
259
+ // isAuthenticated: false,
260
+ // },
261
+ // });
262
+ // localStorage.removeItem(DAUTH_STATE);
263
+ // return;
264
+ // }
265
+ // } catch (error) {
266
+ // dispatch({
267
+ // type: DauthTypes.LOGIN,
268
+ // payload: {
269
+ // user: {} as IDauthUser,
270
+ // domain: {} as IDauthDomainState,
271
+ // isAuthenticated: false,
272
+ // },
273
+ // });
274
+ // localStorage.removeItem(DAUTH_STATE);
275
+ // console.log(error);
276
+ // }
277
+ // }
289
278
 
290
279
  export async function checkTokenAction({
291
280
  dispatch,
@@ -304,27 +293,42 @@ export async function checkTokenAction({
304
293
  if (refreshAccessTokenFetch.response.status === 200) {
305
294
  return;
306
295
  } else {
307
- dispatch({
308
- type: DauthTypes.LOGIN,
309
- payload: {
310
- user: {} as IDauthUser,
311
- domain: {} as IDauthDomainState,
312
- isAuthenticated: false,
313
- },
314
- });
315
- localStorage.removeItem(DAUTH_STATE);
316
- return;
296
+ return resetUser(dispatch);
297
+ // dispatch({
298
+ // type: DauthTypes.LOGIN,
299
+ // payload: {
300
+ // user: {} as IDauthUser,
301
+ // domain: {} as IDauthDomainState,
302
+ // isAuthenticated: false,
303
+ // },
304
+ // });
305
+ // localStorage.removeItem(DAUTH_STATE);
317
306
  }
318
307
  } catch (error) {
319
- dispatch({
320
- type: DauthTypes.LOGIN,
321
- payload: {
322
- user: {} as IDauthUser,
323
- domain: {} as IDauthDomainState,
324
- isAuthenticated: false,
325
- },
326
- });
327
- localStorage.removeItem(DAUTH_STATE);
308
+ resetUser(dispatch);
309
+ // dispatch({
310
+ // type: DauthTypes.LOGIN,
311
+ // payload: {
312
+ // user: {} as IDauthUser,
313
+ // domain: {} as IDauthDomainState,
314
+ // isAuthenticated: false,
315
+ // },
316
+ // });
317
+ // localStorage.removeItem(DAUTH_STATE);
328
318
  throw error;
329
319
  }
330
320
  }
321
+
322
+ ///////////////////////////////////////////
323
+ //////////////////////////////////////////
324
+ const resetUser = (dispatch: any) => {
325
+ localStorage.removeItem(DAUTH_STATE);
326
+ return dispatch({
327
+ type: DauthTypes.LOGIN,
328
+ payload: {
329
+ user: {} as IDauthUser,
330
+ domain: {} as IDauthDomainState,
331
+ isAuthenticated: false,
332
+ },
333
+ });
334
+ };