dauth-context-react 1.0.1 → 1.0.2

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.
@@ -20,7 +20,7 @@ export const getUserAPI = async (
20
20
  },
21
21
  };
22
22
  const response = await fetch(
23
- `${getServerBasePath({ domainName })}/tenant/${domainName}/user`,
23
+ `${getServerBasePath()}/app/${domainName}/user`,
24
24
  params
25
25
  );
26
26
  const data = await response.json();
@@ -41,7 +41,7 @@ export const updateUserAPI = async (
41
41
  body: JSON.stringify(user),
42
42
  };
43
43
  const response = await fetch(
44
- `${getServerBasePath({ domainName })}/tenant/${domainName}/user`,
44
+ `${getServerBasePath()}/app/${domainName}/user`,
45
45
  params
46
46
  );
47
47
  const data = await response.json();
@@ -60,9 +60,7 @@ export const sendEmailVerificationAPI = async (
60
60
  },
61
61
  };
62
62
  const response = await fetch(
63
- `${getServerBasePath({
64
- domainName,
65
- })}/tenant/${domainName}/resend-email-verification`,
63
+ `${getServerBasePath()}/app/${domainName}/resend-email-verification`,
66
64
  params
67
65
  );
68
66
  const data = await response.json();
@@ -81,9 +79,7 @@ export const refreshAccessTokenAPI = async (
81
79
  },
82
80
  };
83
81
  const response = await fetch(
84
- `${getServerBasePath({
85
- domainName,
86
- })}/tenant/${domainName}/refresh-access-token`,
82
+ `${getServerBasePath()}/app/${domainName}/refresh-access-token`,
87
83
  params
88
84
  );
89
85
  const data = await response.json();
@@ -108,9 +104,7 @@ export const verifyTokenAPI = async ({
108
104
  body: JSON.stringify({ tsk }),
109
105
  };
110
106
  const response = await fetch(
111
- `${getServerBasePath({
112
- domainName,
113
- })}/tenant/${domainName}/verify-token`,
107
+ `${getServerBasePath()}/app/${domainName}/verify-token`,
114
108
  params
115
109
  );
116
110
  const data = await response.json();
@@ -10,26 +10,22 @@ function checkIsLocalhost(): boolean {
10
10
  hostname.match(
11
11
  /(192)\.(168)\.(1)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gm
12
12
  ) ||
13
- hostname.match(
14
- /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
15
- )
13
+ hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
16
14
  );
17
15
  }
18
16
 
19
- export function getServerBasePath({ domainName }: { domainName: string }) {
17
+ export function getServerBasePath() {
20
18
  const isLocalhost = checkIsLocalhost();
21
19
  const serverPort = 4012;
22
20
  const serverLocalUrl = `${window.location.protocol}//${window.location.hostname}:${serverPort}/api/${apiVersion}`;
23
- const serverProdUrl = `https://${domainName}.${serverDomain}/api/${apiVersion}`;
24
- const serverBasePath = isLocalhost ? serverLocalUrl : serverProdUrl;
25
- return serverBasePath;
21
+ const serverProdUrl = `https://${serverDomain}/api/${apiVersion}`;
22
+ return isLocalhost ? serverLocalUrl : serverProdUrl;
26
23
  }
27
24
 
28
- export function getClientBasePath({ domainName }: { domainName: string }) {
25
+ export function getClientBasePath() {
29
26
  const isLocalhost = checkIsLocalhost();
30
27
  const clientPort = 5185;
31
28
  const clientLocalUrl = `${window.location.protocol}//${window.location.hostname}:${clientPort}`;
32
- const clientProdUrl = `https://${domainName}.${serverDomain}`;
33
- const clientBasePath = isLocalhost ? clientLocalUrl : clientProdUrl;
34
- return clientBasePath;
29
+ const clientProdUrl = `https://${serverDomain}`;
30
+ return isLocalhost ? clientLocalUrl : clientProdUrl;
35
31
  }
package/src/index.tsx CHANGED
@@ -118,7 +118,7 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
118
118
 
119
119
  const loginWithRedirect = useCallback(() => {
120
120
  return window.location.replace(
121
- `${getClientBasePath({ domainName })}/${domainName}/${routes.signin}`
121
+ `${getClientBasePath()}/${domainName}/${routes.signin}`
122
122
  );
123
123
  }, [domainName]);
124
124
 
@@ -165,7 +165,7 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
165
165
  const token_ls = localStorage.getItem(TOKEN_LS);
166
166
  if (!token_ls) return;
167
167
  return window.location.replace(
168
- `${getClientBasePath({ domainName })}/${domainName}/${routes.updateUser}/${token_ls}`
168
+ `${getClientBasePath()}/${domainName}/${routes.updateUser}/${token_ls}`
169
169
  );
170
170
  }, [domainName]);
171
171
 
@@ -7,7 +7,10 @@ import {
7
7
 
8
8
  const initialDauthState: IDauthState = {
9
9
  user: {
10
- language: (typeof window !== 'undefined' ? window.document.documentElement.getAttribute('lang') : null) || 'es',
10
+ language:
11
+ (typeof window !== 'undefined'
12
+ ? window.document.documentElement.getAttribute('lang')
13
+ : null) || 'es',
11
14
  } as IDauthUser,
12
15
  domain: {} as IDauthDomainState,
13
16
  isLoading: true,
@@ -87,13 +87,13 @@ export async function setAutoLoginAction({
87
87
  return;
88
88
  } else {
89
89
  window.location.replace(
90
- `${getClientBasePath({ domainName })}/${domainName}/${routes.signin}`
90
+ `${getClientBasePath()}/${domainName}/${routes.signin}`
91
91
  );
92
92
  return resetUser(dispatch);
93
93
  }
94
94
  } else {
95
95
  window.location.replace(
96
- `${getClientBasePath({ domainName })}/${domainName}/${routes.signin}`
96
+ `${getClientBasePath()}/${domainName}/${routes.signin}`
97
97
  );
98
98
  return resetUser(dispatch);
99
99
  }
@@ -244,12 +244,15 @@ export async function checkTokenAction({
244
244
  );
245
245
  if (refreshAccessTokenFetch.response.status === 200) {
246
246
  if (refreshAccessTokenFetch.data.accessToken) {
247
- localStorage.setItem(TOKEN_LS, refreshAccessTokenFetch.data.accessToken);
247
+ localStorage.setItem(
248
+ TOKEN_LS,
249
+ refreshAccessTokenFetch.data.accessToken
250
+ );
248
251
  }
249
252
  return;
250
253
  } else {
251
254
  window.location.replace(
252
- `${getClientBasePath({ domainName })}/${domainName}/${routes.signin}`
255
+ `${getClientBasePath()}/${domainName}/${routes.signin}`
253
256
  );
254
257
  return resetUser(dispatch);
255
258
  }