dauth-context-react 0.2.103 → 0.2.105
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/dauth-context-react.cjs.development.js +16 -19
- 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 +16 -19
- package/dist/dauth-context-react.esm.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/initialDauthState.d.ts +5 -7
- package/dist/reducer/dauth.actions.d.ts +2 -4
- package/package.json +1 -1
- package/src/api/dauth.api.ts +4 -1
- package/src/index.tsx +11 -12
- package/src/initialDauthState.ts +6 -8
- package/src/reducer/dauth.actions.ts +3 -7
package/src/index.tsx
CHANGED
|
@@ -15,14 +15,13 @@ import { routes } from './routes';
|
|
|
15
15
|
|
|
16
16
|
interface DauthProviderProps {
|
|
17
17
|
domainName: string;
|
|
18
|
-
sid: string;
|
|
19
18
|
children: React.ReactNode;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
export const DauthProvider: React.FC<DauthProviderProps> = (
|
|
23
22
|
props: DauthProviderProps
|
|
24
23
|
) => {
|
|
25
|
-
const { domainName,
|
|
24
|
+
const { domainName, children } = props;
|
|
26
25
|
const [dauthState, dispatch] = useReducer(userReducer, initialDauthState);
|
|
27
26
|
|
|
28
27
|
// Check token periodically
|
|
@@ -31,7 +30,7 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
|
|
|
31
30
|
let interval = setInterval(() => {
|
|
32
31
|
const token_ls = localStorage.getItem(TOKEN_LS);
|
|
33
32
|
if (!token_ls) return;
|
|
34
|
-
action.checkTokenAction({ dispatch, domainName,
|
|
33
|
+
action.checkTokenAction({ dispatch, domainName, token: token_ls });
|
|
35
34
|
}, 1000 * 60 * 2);
|
|
36
35
|
return () => clearInterval(interval);
|
|
37
36
|
}, []);
|
|
@@ -51,15 +50,15 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
|
|
|
51
50
|
useEffect(() => {
|
|
52
51
|
const dauth_state_ls = localStorage.getItem(TOKEN_LS);
|
|
53
52
|
if (dauth_state_ls && !dauthState.isAuthenticated) {
|
|
54
|
-
action.setAutoLoginAction({ dispatch, dauth_state_ls, domainName
|
|
53
|
+
action.setAutoLoginAction({ dispatch, dauth_state_ls, domainName });
|
|
55
54
|
}
|
|
56
55
|
}, []);
|
|
57
56
|
|
|
58
57
|
const loginWithRedirect = useCallback(() => {
|
|
59
58
|
return window.location.replace(
|
|
60
|
-
`${getClientBasePath({ domainName })}/${routes.tenantSignin}/${
|
|
59
|
+
`${getClientBasePath({ domainName })}/${routes.tenantSignin}/${domainName}`
|
|
61
60
|
);
|
|
62
|
-
}, [domainName,
|
|
61
|
+
}, [domainName, domainName]);
|
|
63
62
|
|
|
64
63
|
const logout = useCallback(() => {
|
|
65
64
|
return action.setLogoutAction({ dispatch });
|
|
@@ -75,8 +74,8 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
|
|
|
75
74
|
name,
|
|
76
75
|
lastname,
|
|
77
76
|
nickname,
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
telPrefix,
|
|
78
|
+
telSuffix,
|
|
80
79
|
language,
|
|
81
80
|
avatar,
|
|
82
81
|
}: Partial<IDauthUser>) => {
|
|
@@ -85,8 +84,8 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
|
|
|
85
84
|
name,
|
|
86
85
|
lastname,
|
|
87
86
|
nickname,
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
telPrefix,
|
|
88
|
+
telSuffix,
|
|
90
89
|
language,
|
|
91
90
|
avatar,
|
|
92
91
|
} as Partial<IDauthUser>;
|
|
@@ -106,9 +105,9 @@ export const DauthProvider: React.FC<DauthProviderProps> = (
|
|
|
106
105
|
return window.location.replace(
|
|
107
106
|
`${getClientBasePath({ domainName })}/${
|
|
108
107
|
routes.tenantUpdateUser
|
|
109
|
-
}/${
|
|
108
|
+
}/${domainName}/${token_ls}`
|
|
110
109
|
);
|
|
111
|
-
}, [domainName,
|
|
110
|
+
}, [domainName, domainName]);
|
|
112
111
|
|
|
113
112
|
const sendEmailVerification = useCallback(async () => {
|
|
114
113
|
const token_ls = localStorage.getItem(TOKEN_LS);
|
package/src/initialDauthState.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
export interface IDauthUser {
|
|
2
2
|
_id: string;
|
|
3
|
-
dauthLicense?: string;
|
|
4
|
-
sid: string;
|
|
5
3
|
name: string;
|
|
6
4
|
lastname: string;
|
|
7
5
|
nickname: string;
|
|
8
6
|
email: string;
|
|
9
|
-
|
|
7
|
+
isVerified: boolean;
|
|
10
8
|
language: string;
|
|
11
9
|
avatar: {
|
|
12
10
|
id: string;
|
|
13
11
|
url: string;
|
|
14
12
|
};
|
|
15
13
|
role: string;
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
telPrefix: string;
|
|
15
|
+
telSuffix: string;
|
|
18
16
|
createdAt: Date;
|
|
19
17
|
updatedAt: Date;
|
|
20
|
-
|
|
18
|
+
lastLogin: Date;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
export interface IDauthDomainState {
|
|
@@ -38,8 +36,8 @@ export interface IDauthState {
|
|
|
38
36
|
name,
|
|
39
37
|
lastname,
|
|
40
38
|
nickname,
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
telPrefix,
|
|
40
|
+
telSuffix,
|
|
43
41
|
language,
|
|
44
42
|
avatar,
|
|
45
43
|
}: Partial<IDauthUser>) => Promise<boolean>;
|
|
@@ -56,13 +56,11 @@ type TSetAutoLoginAction = {
|
|
|
56
56
|
dispatch: React.Dispatch<any>;
|
|
57
57
|
dauth_state_ls: string;
|
|
58
58
|
domainName: string;
|
|
59
|
-
sid: string;
|
|
60
59
|
};
|
|
61
60
|
export async function setAutoLoginAction({
|
|
62
61
|
dispatch,
|
|
63
62
|
dauth_state_ls,
|
|
64
63
|
domainName,
|
|
65
|
-
sid,
|
|
66
64
|
}: TSetAutoLoginAction) {
|
|
67
65
|
dispatch({ type: DauthTypes.SET_IS_LOADING, payload: { isLoading: true } });
|
|
68
66
|
try {
|
|
@@ -88,13 +86,13 @@ export async function setAutoLoginAction({
|
|
|
88
86
|
return;
|
|
89
87
|
} else {
|
|
90
88
|
window.location.replace(
|
|
91
|
-
`${getClientBasePath({ domainName })}/${routes.tenantSignin}/${
|
|
89
|
+
`${getClientBasePath({ domainName })}/${routes.tenantSignin}/${domainName}`
|
|
92
90
|
);
|
|
93
91
|
return resetUser(dispatch);
|
|
94
92
|
}
|
|
95
93
|
} else {
|
|
96
94
|
window.location.replace(
|
|
97
|
-
`${getClientBasePath({ domainName })}/${routes.tenantSignin}/${
|
|
95
|
+
`${getClientBasePath({ domainName })}/${routes.tenantSignin}/${domainName}`
|
|
98
96
|
);
|
|
99
97
|
return resetUser(dispatch);
|
|
100
98
|
}
|
|
@@ -232,12 +230,10 @@ export async function sendEmailVerificationAction({
|
|
|
232
230
|
export async function checkTokenAction({
|
|
233
231
|
dispatch,
|
|
234
232
|
domainName,
|
|
235
|
-
sid,
|
|
236
233
|
token,
|
|
237
234
|
}: {
|
|
238
235
|
dispatch: React.Dispatch<any>;
|
|
239
236
|
domainName: string;
|
|
240
|
-
sid: string;
|
|
241
237
|
token: string;
|
|
242
238
|
}) {
|
|
243
239
|
try {
|
|
@@ -249,7 +245,7 @@ export async function checkTokenAction({
|
|
|
249
245
|
return;
|
|
250
246
|
} else {
|
|
251
247
|
window.location.replace(
|
|
252
|
-
`${getClientBasePath({ domainName })}/${routes.tenantSignin}/${
|
|
248
|
+
`${getClientBasePath({ domainName })}/${routes.tenantSignin}/${domainName}`
|
|
253
249
|
);
|
|
254
250
|
return resetUser(dispatch);
|
|
255
251
|
}
|