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.
- package/dist/api/utils/config.d.ts +2 -6
- package/dist/api/utils/routes.d.ts +2 -2
- package/dist/dauth-context-react.cjs.development.js +18 -42
- 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 +18 -42
- package/dist/dauth-context-react.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/api/dauth.api.ts +5 -11
- package/src/api/utils/config.ts +7 -11
- package/src/api/utils/routes.ts +2 -2
- package/src/index.tsx +2 -6
- package/src/initialDauthState.ts +4 -1
- package/src/reducer/dauth.actions.ts +7 -8
package/src/api/dauth.api.ts
CHANGED
|
@@ -20,7 +20,7 @@ export const getUserAPI = async (
|
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
const response = await fetch(
|
|
23
|
-
`${getServerBasePath(
|
|
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(
|
|
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();
|
package/src/api/utils/config.ts
CHANGED
|
@@ -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(
|
|
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://${
|
|
24
|
-
|
|
25
|
-
return serverBasePath;
|
|
21
|
+
const serverProdUrl = `https://${serverDomain}/api/${apiVersion}`;
|
|
22
|
+
return isLocalhost ? serverLocalUrl : serverProdUrl;
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
export function getClientBasePath(
|
|
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://${
|
|
33
|
-
|
|
34
|
-
return clientBasePath;
|
|
29
|
+
const clientProdUrl = `https://${serverDomain}`;
|
|
30
|
+
return isLocalhost ? clientLocalUrl : clientProdUrl;
|
|
35
31
|
}
|
package/src/api/utils/routes.ts
CHANGED
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({
|
|
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({
|
|
171
|
-
routes.tenantUpdateUser
|
|
172
|
-
}/${domainName}/${token_ls}`
|
|
168
|
+
`${getClientBasePath()}/${domainName}/${routes.updateUser}/${token_ls}`
|
|
173
169
|
);
|
|
174
170
|
}, [domainName]);
|
|
175
171
|
|
package/src/initialDauthState.ts
CHANGED
|
@@ -7,7 +7,10 @@ import {
|
|
|
7
7
|
|
|
8
8
|
const initialDauthState: IDauthState = {
|
|
9
9
|
user: {
|
|
10
|
-
language:
|
|
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({
|
|
90
|
+
`${getClientBasePath()}/${domainName}/${routes.signin}`
|
|
91
91
|
);
|
|
92
92
|
return resetUser(dispatch);
|
|
93
93
|
}
|
|
94
94
|
} else {
|
|
95
95
|
window.location.replace(
|
|
96
|
-
`${getClientBasePath({
|
|
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(
|
|
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({
|
|
255
|
-
routes.tenantSignin
|
|
256
|
-
}/${domainName}`
|
|
255
|
+
`${getClientBasePath()}/${domainName}/${routes.signin}`
|
|
257
256
|
);
|
|
258
257
|
return resetUser(dispatch);
|
|
259
258
|
}
|