dauth-context-react 0.2.110 → 0.2.111

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.
@@ -1,11 +1,18 @@
1
1
  import { routes } from './utils/routes';
2
2
  import { getServerBasePath } from './utils/config';
3
3
  import { IDauthUser } from '../interfaces';
4
+ import {
5
+ IgetUserAPIResponse,
6
+ IrefreshAccessTokenAPIResponse,
7
+ IsendEmailVerificationAPIResponse,
8
+ IupdateUserAPIResponse,
9
+ IverifyTokenAPIResponse,
10
+ } from './interfaces/dauth.api.responses';
4
11
 
5
12
  export const getUserAPI = async (
6
13
  domainName: string,
7
14
  token: string
8
- ): Promise<any> => {
15
+ ): Promise<IgetUserAPIResponse> => {
9
16
  const params = {
10
17
  method: 'GET',
11
18
  headers: {
@@ -27,7 +34,7 @@ export const updateUserAPI = async (
27
34
  domainName: string,
28
35
  user: Partial<IDauthUser>,
29
36
  token: string
30
- ): Promise<any> => {
37
+ ): Promise<IupdateUserAPIResponse> => {
31
38
  const params = {
32
39
  method: 'PATCH',
33
40
  headers: {
@@ -49,7 +56,7 @@ export const updateUserAPI = async (
49
56
  export const sendEmailVerificationAPI = async (
50
57
  domainName: string,
51
58
  token: string
52
- ): Promise<any> => {
59
+ ): Promise<IsendEmailVerificationAPIResponse> => {
53
60
  const params = {
54
61
  method: 'GET',
55
62
  headers: {
@@ -70,7 +77,7 @@ export const sendEmailVerificationAPI = async (
70
77
  export const refreshAccessTokenAPI = async (
71
78
  domainName: string,
72
79
  token: string
73
- ): Promise<any> => {
80
+ ): Promise<IrefreshAccessTokenAPIResponse> => {
74
81
  const params = {
75
82
  method: 'GET',
76
83
  headers: {
@@ -96,7 +103,7 @@ export const verifyTokenAPI = async ({
96
103
  domainName: string;
97
104
  ask: string;
98
105
  token: string;
99
- }): Promise<any> => {
106
+ }): Promise<IverifyTokenAPIResponse> => {
100
107
  const params = {
101
108
  method: 'POST',
102
109
  headers: {
@@ -0,0 +1,43 @@
1
+ import { IDauthDomainState, IDauthUser } from '../../interfaces';
2
+
3
+ export interface IgetUserAPIResponse {
4
+ response: Response;
5
+ data: {
6
+ status: string;
7
+ user: IDauthUser;
8
+ domain: IDauthDomainState;
9
+ };
10
+ }
11
+
12
+ export interface IupdateUserAPIResponse {
13
+ response: Response;
14
+ data: {
15
+ status: string;
16
+ user: IDauthUser;
17
+ message: string;
18
+ };
19
+ }
20
+
21
+ export interface IsendEmailVerificationAPIResponse {
22
+ response: Response;
23
+ data: {
24
+ status: string;
25
+ message: string;
26
+ emailStatus: string;
27
+ };
28
+ }
29
+
30
+ export interface IrefreshAccessTokenAPIResponse {
31
+ response: Response;
32
+ data: {
33
+ accessToken: string;
34
+ };
35
+ }
36
+
37
+ export interface IverifyTokenAPIResponse {
38
+ response: Response;
39
+ data: {
40
+ status: string;
41
+ message: string;
42
+ };
43
+ }
package/src/index.tsx CHANGED
@@ -56,9 +56,10 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
56
56
  token: token_ls,
57
57
  });
58
58
  } else {
59
- return action.setLogoutAction({ dispatch });
59
+ action.setLogoutAction({ dispatch });
60
+ throw new Error('Ask value in DauthProvider is not valid');
60
61
  }
61
- }, 1000 * 60 * 1);
62
+ }, 1000 * 60 * 5);
62
63
  return () => clearInterval(interval);
63
64
  }, [dauthState.isAuthenticated, isValidAsk]);
64
65
 
@@ -78,7 +79,8 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
78
79
  domainName,
79
80
  });
80
81
  } else {
81
- return action.setLogoutAction({ dispatch });
82
+ action.setLogoutAction({ dispatch });
83
+ throw new Error('Ask value in DauthProvider is not valid');
82
84
  }
83
85
  }
84
86
  })();
@@ -93,11 +95,12 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
93
95
  if (isValid) {
94
96
  return action.setAutoLoginAction({
95
97
  dispatch,
96
- dauth_state_ls: token_ls,
98
+ token_ls,
97
99
  domainName,
98
100
  });
99
101
  } else {
100
- return action.setLogoutAction({ dispatch });
102
+ action.setLogoutAction({ dispatch });
103
+ throw new Error('Ask value in DauthProvider is not valid');
101
104
  }
102
105
  }
103
106
  })();
@@ -54,22 +54,22 @@ export async function setDauthStateAction({
54
54
 
55
55
  type TSetAutoLoginAction = {
56
56
  dispatch: React.Dispatch<any>;
57
- dauth_state_ls: string;
57
+ token_ls: string;
58
58
  domainName: string;
59
59
  };
60
60
  export async function setAutoLoginAction({
61
61
  dispatch,
62
- dauth_state_ls,
62
+ token_ls,
63
63
  domainName,
64
64
  }: TSetAutoLoginAction) {
65
65
  dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });
66
66
  try {
67
67
  const refreshAccessTokenFetch = await refreshAccessTokenAPI(
68
68
  domainName,
69
- dauth_state_ls
69
+ token_ls
70
70
  );
71
71
  if (refreshAccessTokenFetch.response.status === 200) {
72
- const getUserFetch = await getUserAPI(domainName, dauth_state_ls);
72
+ const getUserFetch = await getUserAPI(domainName, token_ls);
73
73
  if (getUserFetch.response.status === 200) {
74
74
  dispatch({
75
75
  type: DauthTypes.LOGIN,