dauth-context-react 1.0.0 → 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
  }
@@ -1,4 +1,4 @@
1
1
  export const routes = {
2
- tenantSignin: 'tenant/signin',
3
- tenantUpdateUser: 'tenant/update-user',
2
+ signin: 'signin',
3
+ updateUser: 'update-user',
4
4
  };
package/src/index.tsx CHANGED
@@ -118,9 +118,7 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
118
118
 
119
119
  const loginWithRedirect = useCallback(() => {
120
120
  return window.location.replace(
121
- `${getClientBasePath({ domainName })}/${
122
- routes.tenantSignin
123
- }/${domainName}`
121
+ `${getClientBasePath()}/${domainName}/${routes.signin}`
124
122
  );
125
123
  }, [domainName]);
126
124
 
@@ -167,9 +165,7 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
167
165
  const token_ls = localStorage.getItem(TOKEN_LS);
168
166
  if (!token_ls) return;
169
167
  return window.location.replace(
170
- `${getClientBasePath({ domainName })}/${
171
- routes.tenantUpdateUser
172
- }/${domainName}/${token_ls}`
168
+ `${getClientBasePath()}/${domainName}/${routes.updateUser}/${token_ls}`
173
169
  );
174
170
  }, [domainName]);
175
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,15 +87,13 @@ export async function setAutoLoginAction({
87
87
  return;
88
88
  } else {
89
89
  window.location.replace(
90
- `${getClientBasePath({ domainName })}/${routes.tenantSignin}/${domainName}`
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 })}/${
97
- routes.tenantSignin
98
- }/${domainName}`
96
+ `${getClientBasePath()}/${domainName}/${routes.signin}`
99
97
  );
100
98
  return resetUser(dispatch);
101
99
  }
@@ -246,14 +244,15 @@ export async function checkTokenAction({
246
244
  );
247
245
  if (refreshAccessTokenFetch.response.status === 200) {
248
246
  if (refreshAccessTokenFetch.data.accessToken) {
249
- localStorage.setItem(TOKEN_LS, refreshAccessTokenFetch.data.accessToken);
247
+ localStorage.setItem(
248
+ TOKEN_LS,
249
+ refreshAccessTokenFetch.data.accessToken
250
+ );
250
251
  }
251
252
  return;
252
253
  } else {
253
254
  window.location.replace(
254
- `${getClientBasePath({ domainName })}/${
255
- routes.tenantSignin
256
- }/${domainName}`
255
+ `${getClientBasePath()}/${domainName}/${routes.signin}`
257
256
  );
258
257
  return resetUser(dispatch);
259
258
  }