@frontegg/react-hooks 5.59.1 → 6.0.1-alpha.0
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/FronteggProvider.d.ts +11 -10
- package/FronteggProvider.js +137 -0
- package/FronteggStoreContext.d.ts +8 -8
- package/FronteggStoreContext.js +13 -0
- package/audits/auditLogs.d.ts +5 -5
- package/audits/auditLogs.js +4 -0
- package/audits/auditsMetadata.d.ts +5 -5
- package/audits/auditsMetadata.js +4 -0
- package/audits/hooks.d.ts +12 -12
- package/audits/hooks.js +35 -0
- package/audits/index.d.ts +3 -3
- package/audits/index.js +3 -5
- package/auth/acceptInvitation.d.ts +5 -5
- package/auth/acceptInvitation.js +4 -0
- package/auth/activateAccount.d.ts +5 -5
- package/auth/activateAccount.js +4 -0
- package/auth/apiTokens.d.ts +5 -5
- package/auth/apiTokens.js +4 -0
- package/auth/forgotPassword.d.ts +5 -5
- package/auth/forgotPassword.js +4 -0
- package/auth/hooks.d.ts +62 -62
- package/auth/hooks.js +79 -0
- package/auth/index.d.ts +16 -16
- package/auth/index.js +16 -7
- package/auth/login.d.ts +5 -5
- package/auth/login.js +4 -0
- package/auth/mfa.d.ts +4 -4
- package/auth/mfa.js +4 -0
- package/auth/profile.d.ts +6 -6
- package/auth/profile.js +16 -0
- package/auth/resetPhoneNumber.d.ts +5 -5
- package/auth/resetPhoneNumber.js +4 -0
- package/auth/roles.d.ts +5 -5
- package/auth/roles.js +4 -0
- package/auth/securityPolicy.d.ts +11 -11
- package/auth/securityPolicy.js +25 -0
- package/auth/signup.d.ts +5 -5
- package/auth/signup.js +4 -0
- package/auth/socialLogin.d.ts +5 -5
- package/auth/socialLogin.js +4 -0
- package/auth/sso.d.ts +4 -4
- package/auth/sso.js +4 -0
- package/auth/team.d.ts +5 -5
- package/auth/team.js +4 -0
- package/auth/tenants.d.ts +5 -5
- package/auth/tenants.js +4 -0
- package/common/index.d.ts +17 -17
- package/common/index.js +30 -0
- package/common/package.json +6 -0
- package/connectivity/hooks.d.ts +5 -5
- package/connectivity/hooks.js +15 -0
- package/connectivity/index.d.ts +1 -1
- package/connectivity/index.js +1 -5
- package/index.d.ts +8 -8
- package/index.js +13 -93
- package/node/FronteggProvider.js +160 -0
- package/node/FronteggStoreContext.js +49 -0
- package/node/audits/auditLogs.js +18 -0
- package/node/audits/auditsMetadata.js +18 -0
- package/node/audits/hooks.js +62 -0
- package/node/audits/index.js +46 -13
- package/node/auth/acceptInvitation.js +18 -0
- package/node/auth/activateAccount.js +18 -0
- package/node/auth/apiTokens.js +18 -0
- package/node/auth/forgotPassword.js +18 -0
- package/node/auth/hooks.js +127 -0
- package/node/auth/index.js +275 -54
- package/node/auth/login.js +18 -0
- package/node/auth/mfa.js +18 -0
- package/node/auth/profile.js +34 -0
- package/node/auth/resetPhoneNumber.js +18 -0
- package/node/auth/roles.js +18 -0
- package/node/auth/securityPolicy.js +43 -0
- package/node/auth/signup.js +18 -0
- package/node/auth/socialLogin.js +18 -0
- package/node/auth/sso.js +18 -0
- package/node/auth/team.js +18 -0
- package/node/auth/tenants.js +18 -0
- package/node/common/index.js +44 -0
- package/node/connectivity/hooks.js +31 -0
- package/node/connectivity/index.js +17 -12
- package/node/index.js +111 -187
- package/node/subscriptions/hooks.js +131 -0
- package/node/subscriptions/index.js +15 -27
- package/node/vendor/hooks.js +31 -0
- package/node/vendor/index.js +17 -12
- package/package.json +12 -7
- package/subscriptions/hooks.d.ts +19 -19
- package/subscriptions/hooks.js +69 -0
- package/subscriptions/index.d.ts +1 -1
- package/subscriptions/index.js +1 -5
- package/vendor/hooks.d.ts +5 -5
- package/vendor/hooks.js +15 -0
- package/vendor/index.d.ts +1 -1
- package/vendor/index.js +1 -5
- package/FronteggStoreContext-d6c3b684.js +0 -9
- package/auditsMetadata-9ab88593.js +0 -35
- package/hooks-6400e233.js +0 -14
- package/hooks-7fc5d634.js +0 -64
- package/hooks-eaf879c9.js +0 -14
- package/node/FronteggStoreContext-6cfac56c.js +0 -18
- package/node/auditsMetadata-d15799a1.js +0 -42
- package/node/hooks-429ffd3a.js +0 -83
- package/node/hooks-5d5a445e.js +0 -17
- package/node/hooks-cf739b27.js +0 -17
- package/node/roles-f45dbc50.js +0 -215
- package/roles-f87bc6a0.js +0 -172
package/node/roles-f45dbc50.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var reduxStore = require('@frontegg/redux-store');
|
|
4
|
-
var React = require('react');
|
|
5
|
-
var reactRedux = require('react-redux');
|
|
6
|
-
var FronteggStoreContext = require('./FronteggStoreContext-6cfac56c.js');
|
|
7
|
-
var restApi = require('@frontegg/rest-api');
|
|
8
|
-
var tslib = require('tslib');
|
|
9
|
-
|
|
10
|
-
const ShadowDomContext = React.createContext({});
|
|
11
|
-
const useShadowDom = () => {
|
|
12
|
-
const context = React.useContext(ShadowDomContext);
|
|
13
|
-
const { urlStrategy = 'path', onRedirectTo = urlStrategy === 'path'
|
|
14
|
-
? (path) => window.history.pushState(null, '', path)
|
|
15
|
-
: (path) => window.history.pushState(null, '', `#${path}`), renderByRoute = false, customLoader = false, customStyles, contextOptions } = context, rest = tslib.__rest(context, ["urlStrategy", "onRedirectTo", "renderByRoute", "customLoader", "customStyles", "contextOptions"]);
|
|
16
|
-
return Object.assign({ isShadowDom: true, onRedirectTo,
|
|
17
|
-
renderByRoute,
|
|
18
|
-
customLoader,
|
|
19
|
-
customStyles,
|
|
20
|
-
urlStrategy, contextOptions: Object.assign({ requestCredentials: 'include' }, contextOptions) }, rest);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const defaultMapper = {
|
|
24
|
-
state: (state) => state,
|
|
25
|
-
actions: (actions) => actions,
|
|
26
|
-
};
|
|
27
|
-
const useAuth = (stateMapper = defaultMapper.state) => {
|
|
28
|
-
return FronteggStoreContext.useSelector((state) => stateMapper(state[reduxStore.authStoreName]), reactRedux.shallowEqual);
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* ```jsx
|
|
32
|
-
* export const MyFunctionComponent = () => {
|
|
33
|
-
* const { isAuthenticated, user } = useAuth();
|
|
34
|
-
* const loginWithRedirect = useLoginWithRedirect();
|
|
35
|
-
*
|
|
36
|
-
* if (!isAuthenticated) {
|
|
37
|
-
* loginWithRedirect();
|
|
38
|
-
* return <></>;
|
|
39
|
-
* }
|
|
40
|
-
*
|
|
41
|
-
* return (<div>Hello User {user.name}</div>);
|
|
42
|
-
* }
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* use this frontegg hook function to get if user is "Authenticated"
|
|
46
|
-
*/
|
|
47
|
-
const useLoginWithRedirect = () => {
|
|
48
|
-
const dispatch = FronteggStoreContext.useDispatch();
|
|
49
|
-
return React.useMemo(() => reduxStore.bindActionCreators(reduxStore.authActions.requestHostedLoginAuthorize, dispatch), [reduxStore.authActions.requestHostedLoginAuthorize]);
|
|
50
|
-
};
|
|
51
|
-
const useAuthActions = () => {
|
|
52
|
-
const dispatch = FronteggStoreContext.useDispatch();
|
|
53
|
-
return React.useMemo(() => reduxStore.bindActionCreators(reduxStore.authActions, dispatch), [reduxStore.authActions]);
|
|
54
|
-
};
|
|
55
|
-
const useOnRedirectTo = () => {
|
|
56
|
-
var _a;
|
|
57
|
-
const context = React.useContext(ShadowDomContext);
|
|
58
|
-
return (_a = context === null || context === void 0 ? void 0 : context.onRedirectTo) !== null && _a !== void 0 ? _a : restApi.ContextHolder.onRedirectTo;
|
|
59
|
-
};
|
|
60
|
-
const useAuthRoutes = () => useAuth((state) => (Object.assign({}, state.routes)));
|
|
61
|
-
/**
|
|
62
|
-
* ```jsx
|
|
63
|
-
* export const MyFunctionComponent = () => {
|
|
64
|
-
* const isAuthenticated = useIsAuthenticated();
|
|
65
|
-
* return isAuthenticated ? <div>Hello User</div> : <Redirect to={'/login'}/>
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* use this frontegg hook function to get if user is "Authenticated"
|
|
70
|
-
*/
|
|
71
|
-
const useIsAuthenticated = () => FronteggStoreContext.useSelector(({ [reduxStore.authStoreName]: { isAuthenticated } }) => isAuthenticated, reactRedux.shallowEqual);
|
|
72
|
-
/**
|
|
73
|
-
* ```jsx
|
|
74
|
-
* export const MyFunctionComponent = () => {
|
|
75
|
-
* const user = useAuthUser();
|
|
76
|
-
* return user ? <div>Hello {user.name}!</div> : <div>Hello Guest!</div>
|
|
77
|
-
* }
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
|
-
* use this frontegg hook function to get the authenticated user
|
|
81
|
-
* the return user is null if not authenticated
|
|
82
|
-
*/
|
|
83
|
-
const useAuthUser = () => {
|
|
84
|
-
const routes = useAuthRoutes();
|
|
85
|
-
const onRedirectTo = useOnRedirectTo();
|
|
86
|
-
const user = useAuthUserOrNull();
|
|
87
|
-
if (user == null) {
|
|
88
|
-
onRedirectTo(routes.loginUrl, { refresh: true });
|
|
89
|
-
return {};
|
|
90
|
-
}
|
|
91
|
-
return user;
|
|
92
|
-
};
|
|
93
|
-
const useAuthUserOrNull = () => {
|
|
94
|
-
const { user } = FronteggStoreContext.useSelector(({ [reduxStore.authStoreName]: { user } }) => ({ user }), reactRedux.shallowEqual);
|
|
95
|
-
return user || null;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* hooks helpers
|
|
99
|
-
*/
|
|
100
|
-
const sliceReducerActionsBy = (reducer) => {
|
|
101
|
-
const reducerKeys = Object.keys(reducer);
|
|
102
|
-
const reducerActions = reducerKeys.map((key) => ({ [key]: reduxStore.authActions[key] }));
|
|
103
|
-
return reducerActions.reduce((p, n) => (Object.assign(Object.assign({}, p), n)), {});
|
|
104
|
-
};
|
|
105
|
-
const stateHookGenerator = (stateMapper, subState) => {
|
|
106
|
-
return FronteggStoreContext.useSelector((state) => { var _a; return (_a = stateMapper === null || stateMapper === void 0 ? void 0 : stateMapper(state[reduxStore.authStoreName][subState])) !== null && _a !== void 0 ? _a : state[reduxStore.authStoreName][subState]; }, reactRedux.shallowEqual);
|
|
107
|
-
};
|
|
108
|
-
const reducerActionsGenerator = (actions, reducers) => {
|
|
109
|
-
const dispatch = FronteggStoreContext.useDispatch();
|
|
110
|
-
return React.useMemo(() => reduxStore.bindActionCreators(Object.assign(Object.assign({}, actions), sliceReducerActionsBy(reducers)), dispatch), [dispatch]);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const useAcceptInvitationState = (stateMapper) => stateHookGenerator(stateMapper, 'acceptInvitationState');
|
|
114
|
-
const useAcceptInvitationActions = () => reducerActionsGenerator(reduxStore.acceptInvitationActions, reduxStore.acceptInvitationReducers);
|
|
115
|
-
|
|
116
|
-
const useActivateAccountState = (stateMapper) => stateHookGenerator(stateMapper, 'activateState');
|
|
117
|
-
const useActivateAccountActions = () => reducerActionsGenerator(reduxStore.activateAccountActions, reduxStore.activateAccountReducers);
|
|
118
|
-
|
|
119
|
-
const useApiTokensState = (stateMapper) => stateHookGenerator(stateMapper, 'apiTokensState');
|
|
120
|
-
const useApiTokensActions = () => reducerActionsGenerator(reduxStore.apiTokensActions, reduxStore.apiTokensReducers);
|
|
121
|
-
|
|
122
|
-
const useForgotPasswordState = (stateMapper) => stateHookGenerator(stateMapper, 'forgotPasswordState');
|
|
123
|
-
const useForgotPasswordActions = () => reducerActionsGenerator(reduxStore.forgotPasswordActions, reduxStore.forgotPasswordReducers);
|
|
124
|
-
|
|
125
|
-
const useResetPhoneNumberState = (stateMapper) => stateHookGenerator(stateMapper, 'resetPhoneNumberState');
|
|
126
|
-
const useResetPhoneNumberActions = () => reducerActionsGenerator(reduxStore.resetPhoneNumberActions, reduxStore.resetPhoneNumberReducers);
|
|
127
|
-
|
|
128
|
-
const useLoginState = (stateMapper) => stateHookGenerator(stateMapper, 'loginState');
|
|
129
|
-
const useLoginActions = () => reducerActionsGenerator(reduxStore.loginActions, reduxStore.loginReducers);
|
|
130
|
-
|
|
131
|
-
const useMfaState = (stateMapper) => stateHookGenerator(stateMapper, 'mfaState');
|
|
132
|
-
const useMfaActions = () => reducerActionsGenerator(reduxStore.mfaActions, reduxStore.mfaReducers);
|
|
133
|
-
|
|
134
|
-
const reloadProfileIfNeeded = () => {
|
|
135
|
-
const { loading } = useProfileState();
|
|
136
|
-
const { loadProfile } = useProfileActions();
|
|
137
|
-
React.useEffect(() => {
|
|
138
|
-
!loading && loadProfile();
|
|
139
|
-
}, []);
|
|
140
|
-
};
|
|
141
|
-
const useProfileState = (stateMapper) => stateHookGenerator(stateMapper, 'profileState');
|
|
142
|
-
const useProfileActions = () => reducerActionsGenerator(reduxStore.profileActions, reduxStore.profileReducers);
|
|
143
|
-
|
|
144
|
-
const useSignUpState = (stateMapper) => stateHookGenerator(stateMapper, 'signUpState');
|
|
145
|
-
const useSignUpActions = () => reducerActionsGenerator(reduxStore.signUpActions, reduxStore.signUpReducers);
|
|
146
|
-
|
|
147
|
-
const useSocialLoginState = (stateMapper) => stateHookGenerator(stateMapper, 'socialLoginState');
|
|
148
|
-
const useSocialLoginActions = () => reducerActionsGenerator(reduxStore.socialLoginsActions, reduxStore.socialLoginsReducer);
|
|
149
|
-
|
|
150
|
-
const useAuthTeamState = (stateMapper) => stateHookGenerator(stateMapper, 'teamState');
|
|
151
|
-
const useAuthTeamActions = () => reducerActionsGenerator(reduxStore.teamActions, reduxStore.teamReducers);
|
|
152
|
-
|
|
153
|
-
const useSSOState = (stateMapper) => stateHookGenerator(stateMapper, 'ssoState');
|
|
154
|
-
const useSSOActions = () => reducerActionsGenerator(reduxStore.ssoActions, reduxStore.ssoReducers);
|
|
155
|
-
|
|
156
|
-
const useSecurityPolicyState = (stateMapper) => stateHookGenerator(stateMapper, 'securityPolicyState');
|
|
157
|
-
const useSecurityPolicyActions = () => reducerActionsGenerator(reduxStore.securityPolicyActions, reduxStore.securityPolicyReducers);
|
|
158
|
-
const usePublicPolicySettings = (loadOnMount = false) => {
|
|
159
|
-
const { loading, policy, saving, error } = useSecurityPolicyState(state => state.publicPolicy);
|
|
160
|
-
const { loadPublicSecurityPolicy } = useSecurityPolicyActions();
|
|
161
|
-
React.useEffect(() => {
|
|
162
|
-
(loadOnMount || !policy) && loadPublicSecurityPolicy();
|
|
163
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
164
|
-
}, [loadOnMount, loadPublicSecurityPolicy]);
|
|
165
|
-
return { loading, saving, error, policy };
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const useTenantsState = (stateMapper) => stateHookGenerator(stateMapper, 'tenantsState');
|
|
169
|
-
const useTenantsActions = () => reducerActionsGenerator(reduxStore.tenantsActions, reduxStore.tenantsReducers);
|
|
170
|
-
|
|
171
|
-
const useRolesState = (stateMapper) => stateHookGenerator(stateMapper, 'rolesState');
|
|
172
|
-
const useRolesActions = () => reducerActionsGenerator(reduxStore.rolesActions, reduxStore.rolesReducers);
|
|
173
|
-
|
|
174
|
-
exports.ShadowDomContext = ShadowDomContext;
|
|
175
|
-
exports.reloadProfileIfNeeded = reloadProfileIfNeeded;
|
|
176
|
-
exports.useAcceptInvitationActions = useAcceptInvitationActions;
|
|
177
|
-
exports.useAcceptInvitationState = useAcceptInvitationState;
|
|
178
|
-
exports.useActivateAccountActions = useActivateAccountActions;
|
|
179
|
-
exports.useActivateAccountState = useActivateAccountState;
|
|
180
|
-
exports.useApiTokensActions = useApiTokensActions;
|
|
181
|
-
exports.useApiTokensState = useApiTokensState;
|
|
182
|
-
exports.useAuth = useAuth;
|
|
183
|
-
exports.useAuthActions = useAuthActions;
|
|
184
|
-
exports.useAuthRoutes = useAuthRoutes;
|
|
185
|
-
exports.useAuthTeamActions = useAuthTeamActions;
|
|
186
|
-
exports.useAuthTeamState = useAuthTeamState;
|
|
187
|
-
exports.useAuthUser = useAuthUser;
|
|
188
|
-
exports.useAuthUserOrNull = useAuthUserOrNull;
|
|
189
|
-
exports.useForgotPasswordActions = useForgotPasswordActions;
|
|
190
|
-
exports.useForgotPasswordState = useForgotPasswordState;
|
|
191
|
-
exports.useIsAuthenticated = useIsAuthenticated;
|
|
192
|
-
exports.useLoginActions = useLoginActions;
|
|
193
|
-
exports.useLoginState = useLoginState;
|
|
194
|
-
exports.useLoginWithRedirect = useLoginWithRedirect;
|
|
195
|
-
exports.useMfaActions = useMfaActions;
|
|
196
|
-
exports.useMfaState = useMfaState;
|
|
197
|
-
exports.useOnRedirectTo = useOnRedirectTo;
|
|
198
|
-
exports.useProfileActions = useProfileActions;
|
|
199
|
-
exports.useProfileState = useProfileState;
|
|
200
|
-
exports.usePublicPolicySettings = usePublicPolicySettings;
|
|
201
|
-
exports.useResetPhoneNumberActions = useResetPhoneNumberActions;
|
|
202
|
-
exports.useResetPhoneNumberState = useResetPhoneNumberState;
|
|
203
|
-
exports.useRolesActions = useRolesActions;
|
|
204
|
-
exports.useRolesState = useRolesState;
|
|
205
|
-
exports.useSSOActions = useSSOActions;
|
|
206
|
-
exports.useSSOState = useSSOState;
|
|
207
|
-
exports.useSecurityPolicyActions = useSecurityPolicyActions;
|
|
208
|
-
exports.useSecurityPolicyState = useSecurityPolicyState;
|
|
209
|
-
exports.useShadowDom = useShadowDom;
|
|
210
|
-
exports.useSignUpActions = useSignUpActions;
|
|
211
|
-
exports.useSignUpState = useSignUpState;
|
|
212
|
-
exports.useSocialLoginActions = useSocialLoginActions;
|
|
213
|
-
exports.useSocialLoginState = useSocialLoginState;
|
|
214
|
-
exports.useTenantsActions = useTenantsActions;
|
|
215
|
-
exports.useTenantsState = useTenantsState;
|
package/roles-f87bc6a0.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { authStoreName, bindActionCreators, authActions, acceptInvitationActions, acceptInvitationReducers, activateAccountActions, activateAccountReducers, apiTokensActions, apiTokensReducers, forgotPasswordActions, forgotPasswordReducers, resetPhoneNumberActions, resetPhoneNumberReducers, loginActions, loginReducers, mfaActions, mfaReducers, profileActions, profileReducers, signUpActions, signUpReducers, socialLoginsActions, socialLoginsReducer, teamActions, teamReducers, ssoActions, ssoReducers, securityPolicyActions, securityPolicyReducers, tenantsActions, tenantsReducers, rolesActions, rolesReducers } from '@frontegg/redux-store';
|
|
2
|
-
import { createContext, useContext, useMemo, useEffect } from 'react';
|
|
3
|
-
import { shallowEqual } from 'react-redux';
|
|
4
|
-
import { u as useSelector, a as useDispatch } from './FronteggStoreContext-d6c3b684.js';
|
|
5
|
-
import { ContextHolder } from '@frontegg/rest-api';
|
|
6
|
-
import { __rest } from 'tslib';
|
|
7
|
-
|
|
8
|
-
const ShadowDomContext = createContext({});
|
|
9
|
-
const useShadowDom = () => {
|
|
10
|
-
const context = useContext(ShadowDomContext);
|
|
11
|
-
const { urlStrategy = 'path', onRedirectTo = urlStrategy === 'path'
|
|
12
|
-
? (path) => window.history.pushState(null, '', path)
|
|
13
|
-
: (path) => window.history.pushState(null, '', `#${path}`), renderByRoute = false, customLoader = false, customStyles, contextOptions } = context, rest = __rest(context, ["urlStrategy", "onRedirectTo", "renderByRoute", "customLoader", "customStyles", "contextOptions"]);
|
|
14
|
-
return Object.assign({ isShadowDom: true, onRedirectTo,
|
|
15
|
-
renderByRoute,
|
|
16
|
-
customLoader,
|
|
17
|
-
customStyles,
|
|
18
|
-
urlStrategy, contextOptions: Object.assign({ requestCredentials: 'include' }, contextOptions) }, rest);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const defaultMapper = {
|
|
22
|
-
state: (state) => state,
|
|
23
|
-
actions: (actions) => actions,
|
|
24
|
-
};
|
|
25
|
-
const useAuth = (stateMapper = defaultMapper.state) => {
|
|
26
|
-
return useSelector((state) => stateMapper(state[authStoreName]), shallowEqual);
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* ```jsx
|
|
30
|
-
* export const MyFunctionComponent = () => {
|
|
31
|
-
* const { isAuthenticated, user } = useAuth();
|
|
32
|
-
* const loginWithRedirect = useLoginWithRedirect();
|
|
33
|
-
*
|
|
34
|
-
* if (!isAuthenticated) {
|
|
35
|
-
* loginWithRedirect();
|
|
36
|
-
* return <></>;
|
|
37
|
-
* }
|
|
38
|
-
*
|
|
39
|
-
* return (<div>Hello User {user.name}</div>);
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* use this frontegg hook function to get if user is "Authenticated"
|
|
44
|
-
*/
|
|
45
|
-
const useLoginWithRedirect = () => {
|
|
46
|
-
const dispatch = useDispatch();
|
|
47
|
-
return useMemo(() => bindActionCreators(authActions.requestHostedLoginAuthorize, dispatch), [authActions.requestHostedLoginAuthorize]);
|
|
48
|
-
};
|
|
49
|
-
const useAuthActions = () => {
|
|
50
|
-
const dispatch = useDispatch();
|
|
51
|
-
return useMemo(() => bindActionCreators(authActions, dispatch), [authActions]);
|
|
52
|
-
};
|
|
53
|
-
const useOnRedirectTo = () => {
|
|
54
|
-
var _a;
|
|
55
|
-
const context = useContext(ShadowDomContext);
|
|
56
|
-
return (_a = context === null || context === void 0 ? void 0 : context.onRedirectTo) !== null && _a !== void 0 ? _a : ContextHolder.onRedirectTo;
|
|
57
|
-
};
|
|
58
|
-
const useAuthRoutes = () => useAuth((state) => (Object.assign({}, state.routes)));
|
|
59
|
-
/**
|
|
60
|
-
* ```jsx
|
|
61
|
-
* export const MyFunctionComponent = () => {
|
|
62
|
-
* const isAuthenticated = useIsAuthenticated();
|
|
63
|
-
* return isAuthenticated ? <div>Hello User</div> : <Redirect to={'/login'}/>
|
|
64
|
-
* }
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
|
-
* use this frontegg hook function to get if user is "Authenticated"
|
|
68
|
-
*/
|
|
69
|
-
const useIsAuthenticated = () => useSelector(({ [authStoreName]: { isAuthenticated } }) => isAuthenticated, shallowEqual);
|
|
70
|
-
/**
|
|
71
|
-
* ```jsx
|
|
72
|
-
* export const MyFunctionComponent = () => {
|
|
73
|
-
* const user = useAuthUser();
|
|
74
|
-
* return user ? <div>Hello {user.name}!</div> : <div>Hello Guest!</div>
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* use this frontegg hook function to get the authenticated user
|
|
79
|
-
* the return user is null if not authenticated
|
|
80
|
-
*/
|
|
81
|
-
const useAuthUser = () => {
|
|
82
|
-
const routes = useAuthRoutes();
|
|
83
|
-
const onRedirectTo = useOnRedirectTo();
|
|
84
|
-
const user = useAuthUserOrNull();
|
|
85
|
-
if (user == null) {
|
|
86
|
-
onRedirectTo(routes.loginUrl, { refresh: true });
|
|
87
|
-
return {};
|
|
88
|
-
}
|
|
89
|
-
return user;
|
|
90
|
-
};
|
|
91
|
-
const useAuthUserOrNull = () => {
|
|
92
|
-
const { user } = useSelector(({ [authStoreName]: { user } }) => ({ user }), shallowEqual);
|
|
93
|
-
return user || null;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* hooks helpers
|
|
97
|
-
*/
|
|
98
|
-
const sliceReducerActionsBy = (reducer) => {
|
|
99
|
-
const reducerKeys = Object.keys(reducer);
|
|
100
|
-
const reducerActions = reducerKeys.map((key) => ({ [key]: authActions[key] }));
|
|
101
|
-
return reducerActions.reduce((p, n) => (Object.assign(Object.assign({}, p), n)), {});
|
|
102
|
-
};
|
|
103
|
-
const stateHookGenerator = (stateMapper, subState) => {
|
|
104
|
-
return useSelector((state) => { var _a; return (_a = stateMapper === null || stateMapper === void 0 ? void 0 : stateMapper(state[authStoreName][subState])) !== null && _a !== void 0 ? _a : state[authStoreName][subState]; }, shallowEqual);
|
|
105
|
-
};
|
|
106
|
-
const reducerActionsGenerator = (actions, reducers) => {
|
|
107
|
-
const dispatch = useDispatch();
|
|
108
|
-
return useMemo(() => bindActionCreators(Object.assign(Object.assign({}, actions), sliceReducerActionsBy(reducers)), dispatch), [dispatch]);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const useAcceptInvitationState = (stateMapper) => stateHookGenerator(stateMapper, 'acceptInvitationState');
|
|
112
|
-
const useAcceptInvitationActions = () => reducerActionsGenerator(acceptInvitationActions, acceptInvitationReducers);
|
|
113
|
-
|
|
114
|
-
const useActivateAccountState = (stateMapper) => stateHookGenerator(stateMapper, 'activateState');
|
|
115
|
-
const useActivateAccountActions = () => reducerActionsGenerator(activateAccountActions, activateAccountReducers);
|
|
116
|
-
|
|
117
|
-
const useApiTokensState = (stateMapper) => stateHookGenerator(stateMapper, 'apiTokensState');
|
|
118
|
-
const useApiTokensActions = () => reducerActionsGenerator(apiTokensActions, apiTokensReducers);
|
|
119
|
-
|
|
120
|
-
const useForgotPasswordState = (stateMapper) => stateHookGenerator(stateMapper, 'forgotPasswordState');
|
|
121
|
-
const useForgotPasswordActions = () => reducerActionsGenerator(forgotPasswordActions, forgotPasswordReducers);
|
|
122
|
-
|
|
123
|
-
const useResetPhoneNumberState = (stateMapper) => stateHookGenerator(stateMapper, 'resetPhoneNumberState');
|
|
124
|
-
const useResetPhoneNumberActions = () => reducerActionsGenerator(resetPhoneNumberActions, resetPhoneNumberReducers);
|
|
125
|
-
|
|
126
|
-
const useLoginState = (stateMapper) => stateHookGenerator(stateMapper, 'loginState');
|
|
127
|
-
const useLoginActions = () => reducerActionsGenerator(loginActions, loginReducers);
|
|
128
|
-
|
|
129
|
-
const useMfaState = (stateMapper) => stateHookGenerator(stateMapper, 'mfaState');
|
|
130
|
-
const useMfaActions = () => reducerActionsGenerator(mfaActions, mfaReducers);
|
|
131
|
-
|
|
132
|
-
const reloadProfileIfNeeded = () => {
|
|
133
|
-
const { loading } = useProfileState();
|
|
134
|
-
const { loadProfile } = useProfileActions();
|
|
135
|
-
useEffect(() => {
|
|
136
|
-
!loading && loadProfile();
|
|
137
|
-
}, []);
|
|
138
|
-
};
|
|
139
|
-
const useProfileState = (stateMapper) => stateHookGenerator(stateMapper, 'profileState');
|
|
140
|
-
const useProfileActions = () => reducerActionsGenerator(profileActions, profileReducers);
|
|
141
|
-
|
|
142
|
-
const useSignUpState = (stateMapper) => stateHookGenerator(stateMapper, 'signUpState');
|
|
143
|
-
const useSignUpActions = () => reducerActionsGenerator(signUpActions, signUpReducers);
|
|
144
|
-
|
|
145
|
-
const useSocialLoginState = (stateMapper) => stateHookGenerator(stateMapper, 'socialLoginState');
|
|
146
|
-
const useSocialLoginActions = () => reducerActionsGenerator(socialLoginsActions, socialLoginsReducer);
|
|
147
|
-
|
|
148
|
-
const useAuthTeamState = (stateMapper) => stateHookGenerator(stateMapper, 'teamState');
|
|
149
|
-
const useAuthTeamActions = () => reducerActionsGenerator(teamActions, teamReducers);
|
|
150
|
-
|
|
151
|
-
const useSSOState = (stateMapper) => stateHookGenerator(stateMapper, 'ssoState');
|
|
152
|
-
const useSSOActions = () => reducerActionsGenerator(ssoActions, ssoReducers);
|
|
153
|
-
|
|
154
|
-
const useSecurityPolicyState = (stateMapper) => stateHookGenerator(stateMapper, 'securityPolicyState');
|
|
155
|
-
const useSecurityPolicyActions = () => reducerActionsGenerator(securityPolicyActions, securityPolicyReducers);
|
|
156
|
-
const usePublicPolicySettings = (loadOnMount = false) => {
|
|
157
|
-
const { loading, policy, saving, error } = useSecurityPolicyState(state => state.publicPolicy);
|
|
158
|
-
const { loadPublicSecurityPolicy } = useSecurityPolicyActions();
|
|
159
|
-
useEffect(() => {
|
|
160
|
-
(loadOnMount || !policy) && loadPublicSecurityPolicy();
|
|
161
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
162
|
-
}, [loadOnMount, loadPublicSecurityPolicy]);
|
|
163
|
-
return { loading, saving, error, policy };
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const useTenantsState = (stateMapper) => stateHookGenerator(stateMapper, 'tenantsState');
|
|
167
|
-
const useTenantsActions = () => reducerActionsGenerator(tenantsActions, tenantsReducers);
|
|
168
|
-
|
|
169
|
-
const useRolesState = (stateMapper) => stateHookGenerator(stateMapper, 'rolesState');
|
|
170
|
-
const useRolesActions = () => reducerActionsGenerator(rolesActions, rolesReducers);
|
|
171
|
-
|
|
172
|
-
export { useSignUpActions as A, useSocialLoginState as B, useSocialLoginActions as C, useAuthTeamState as D, useAuthTeamActions as E, useSSOState as F, useSSOActions as G, useSecurityPolicyState as H, useSecurityPolicyActions as I, usePublicPolicySettings as J, useTenantsState as K, useTenantsActions as L, useRolesState as M, useRolesActions as N, useShadowDom as O, ShadowDomContext as S, useAuthActions as a, useOnRedirectTo as b, useAuthRoutes as c, useIsAuthenticated as d, useAuthUser as e, useAuthUserOrNull as f, useLoginWithRedirect as g, useAcceptInvitationState as h, useAcceptInvitationActions as i, useActivateAccountState as j, useActivateAccountActions as k, useApiTokensState as l, useApiTokensActions as m, useForgotPasswordState as n, useForgotPasswordActions as o, useResetPhoneNumberState as p, useResetPhoneNumberActions as q, useLoginState as r, useLoginActions as s, useMfaState as t, useAuth as u, useMfaActions as v, reloadProfileIfNeeded as w, useProfileState as x, useProfileActions as y, useSignUpState as z };
|