@frontegg/react-hooks 6.176.0 → 6.178.0-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/FronteggProvider.d.ts +12 -0
- package/FronteggProvider/FronteggProvider.js +134 -0
- package/FronteggProvider/index.d.ts +1 -12
- package/FronteggProvider/index.js +1 -133
- package/FronteggStoreContext/FronteggStoreContext.d.ts +9 -0
- package/FronteggStoreContext/FronteggStoreContext.js +16 -0
- package/FronteggStoreContext/index.d.ts +1 -13
- package/FronteggStoreContext/index.js +1 -14
- package/audits/auditLogs.d.ts +2 -4
- package/audits/auditLogs.js +8 -6
- package/audits/auditsMetadata.d.ts +2 -4
- package/audits/auditsMetadata.js +8 -6
- package/audits/hooks.d.ts +0 -8
- package/audits/hooks.js +6 -30
- package/auth/acceptInvitation.js +10 -5
- package/auth/activateAccount.js +10 -4
- package/auth/{MSP/allAccounts.d.ts → allAccounts.d.ts} +2 -4
- package/auth/allAccounts.js +20 -0
- package/auth/apiTokens.d.ts +0 -2
- package/auth/apiTokens.js +8 -6
- package/auth/customLogin.d.ts +2 -5
- package/auth/customLogin.js +10 -11
- package/auth/entitlements.d.ts +14 -14
- package/auth/entitlements.js +25 -21
- package/auth/forgotPassword.d.ts +0 -2
- package/auth/forgotPassword.js +8 -6
- package/auth/groups.d.ts +0 -4
- package/auth/groups.js +12 -13
- package/auth/hooks.d.ts +9 -11
- package/auth/hooks.js +27 -58
- package/auth/impersonate.d.ts +0 -2
- package/auth/impersonate.js +7 -6
- package/auth/index.d.ts +14 -17
- package/auth/index.js +15 -18
- package/auth/login.d.ts +1 -1
- package/auth/login.js +13 -4
- package/auth/mfa.d.ts +1 -1
- package/auth/mfa.js +13 -4
- package/auth/passkeys.d.ts +1 -4
- package/auth/passkeys.js +7 -6
- package/auth/profile.d.ts +2 -4
- package/auth/profile.js +9 -8
- package/auth/provisioning.d.ts +1 -3
- package/auth/provisioning.js +7 -6
- package/auth/resetPhoneNumber.d.ts +1 -3
- package/auth/resetPhoneNumber.js +7 -6
- package/auth/roles.d.ts +1 -3
- package/auth/roles.js +7 -6
- package/auth/security/index.d.ts +4 -0
- package/auth/security/index.js +4 -0
- package/auth/security/restrictions.d.ts +0 -2
- package/auth/security/restrictions.js +10 -10
- package/auth/security/securityCenter.d.ts +1 -4
- package/auth/security/securityCenter.js +8 -6
- package/auth/security/securityPolicy.d.ts +5 -11
- package/auth/security/securityPolicy.js +19 -30
- package/auth/security/sessionsPolicy.d.ts +1 -3
- package/auth/security/sessionsPolicy.js +8 -6
- package/auth/sessions.d.ts +1 -3
- package/auth/sessions.js +7 -6
- package/auth/signup.d.ts +1 -1
- package/auth/signup.js +13 -4
- package/auth/sms.d.ts +1 -4
- package/auth/sms.js +7 -6
- package/auth/socialLogin.d.ts +1 -1
- package/auth/socialLogin.js +10 -4
- package/auth/sso.d.ts +1 -1
- package/auth/sso.js +10 -4
- package/auth/{stepUp/stepUp.d.ts → stepUp.d.ts} +0 -2
- package/auth/{stepUp/stepUp.js → stepUp.js} +9 -6
- package/auth/team.d.ts +9 -1
- package/auth/team.js +22 -4
- package/auth/tenants.d.ts +1 -3
- package/auth/tenants.js +8 -6
- package/common/CustomComponentHolder.js +3 -1
- package/common/index.js +3 -3
- package/connectivity/hooks.d.ts +2 -5
- package/connectivity/hooks.js +6 -9
- package/index.d.ts +2 -2
- package/index.js +3 -3
- package/node/FronteggProvider/FronteggProvider.js +140 -0
- package/node/FronteggProvider/index.js +9 -134
- package/node/FronteggStoreContext/FronteggStoreContext.js +26 -0
- package/node/FronteggStoreContext/index.js +11 -35
- package/node/audits/auditLogs.js +8 -6
- package/node/audits/auditsMetadata.js +8 -6
- package/node/audits/hooks.js +7 -34
- package/node/auth/acceptInvitation.js +7 -5
- package/node/auth/activateAccount.js +7 -4
- package/node/auth/allAccounts.js +27 -0
- package/node/auth/apiTokens.js +8 -6
- package/node/auth/customLogin.js +11 -12
- package/node/auth/entitlements.js +24 -20
- package/node/auth/forgotPassword.js +8 -6
- package/node/auth/groups.js +12 -12
- package/node/auth/hooks.js +27 -61
- package/node/auth/impersonate.js +7 -6
- package/node/auth/index.js +84 -120
- package/node/auth/login.js +10 -4
- package/node/auth/mfa.js +10 -4
- package/node/auth/passkeys.js +7 -6
- package/node/auth/profile.js +10 -9
- package/node/auth/provisioning.js +7 -6
- package/node/auth/resetPhoneNumber.js +7 -6
- package/node/auth/roles.js +7 -6
- package/node/auth/security/index.js +49 -0
- package/node/auth/security/restrictions.js +10 -10
- package/node/auth/security/securityCenter.js +8 -6
- package/node/auth/security/securityPolicy.js +16 -30
- package/node/auth/security/sessionsPolicy.js +8 -6
- package/node/auth/sessions.js +7 -6
- package/node/auth/signup.js +10 -4
- package/node/auth/sms.js +7 -6
- package/node/auth/socialLogin.js +7 -4
- package/node/auth/sso.js +7 -4
- package/node/auth/{stepUp/stepUp.js → stepUp.js} +10 -7
- package/node/auth/team.js +25 -4
- package/node/auth/tenants.js +8 -6
- package/node/common/CustomComponentHolder.js +3 -1
- package/node/common/index.js +2 -2
- package/node/connectivity/hooks.js +5 -8
- package/node/index.js +16 -16
- package/node/subscriptions/hooks.js +84 -51
- package/node/vendor/hooks.js +5 -6
- package/package.json +3 -3
- package/subscriptions/hooks.d.ts +32 -10
- package/subscriptions/hooks.js +81 -49
- package/vendor/hooks.d.ts +0 -1
- package/vendor/hooks.js +9 -7
- package/auth/MSP/allAccounts.js +0 -15
- package/auth/stepUp/index.d.ts +0 -2
- package/auth/stepUp/index.js +0 -2
- package/auth/stepUp/interfaces.d.ts +0 -2
- package/auth/stepUp/interfaces.js +0 -1
- package/node/auth/MSP/allAccounts.js +0 -24
- package/node/auth/stepUp/index.js +0 -27
- package/node/auth/stepUp/interfaces.js +0 -5
- package/node/tests/hooks.tsc-test.js +0 -318
- package/tests/hooks.tsc-test.js +0 -317
package/auth/entitlements.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Entitlement, EntitledToOptions } from '@frontegg/redux-store';
|
|
2
1
|
import { CustomAttributes } from '@frontegg/entitlements-javascript-commons';
|
|
2
|
+
import { EntitledToOptions, Entitlement } from '@frontegg/redux-store';
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
4
|
+
@param key feature key
|
|
5
|
+
@param customAttributes user attributes
|
|
6
|
+
@returns if the user is entitled to the given feature and attributes. Attaching the justification if not
|
|
7
|
+
*/
|
|
8
8
|
export declare const useFeatureEntitlements: (key: string, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
|
|
9
9
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
10
|
+
@param key permission key
|
|
11
|
+
@param customAttributes user attributes
|
|
12
|
+
@returns if the user is entitled to the given permission and attributes. Attaching the justification if not
|
|
13
|
+
*/
|
|
14
14
|
export declare const usePermissionEntitlements: (key: string, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
16
|
+
@param entitledToOptions including permission or feature key
|
|
17
|
+
@param customAttributes user attributes
|
|
18
|
+
@returns if the user is entitled to the given feature or permission and attributes (check only one). Attaching the justification if not
|
|
19
|
+
*/
|
|
20
20
|
export declare const useEntitlements: (options: EntitledToOptions, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
|
|
21
21
|
/**
|
|
22
22
|
@param entitledToOptions including permission or feature key
|
|
@@ -27,7 +27,7 @@ export declare const useEntitlementsActions: () => {
|
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
29
|
@returns if the option to use entitlements is enabled
|
|
30
|
-
|
|
30
|
+
*/
|
|
31
31
|
export declare const useEntitlementsOptions: () => {
|
|
32
32
|
isEntitlementsEnabled: boolean;
|
|
33
33
|
isEntitledTo: (options: EntitledToOptions, customAttributes?: Record<string, string | number | boolean | Date> | undefined) => Entitlement;
|
package/auth/entitlements.js
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
import { getPermissionEntitlements, getFeatureEntitlements, getEntitlements } from '@frontegg/redux-store';
|
|
2
1
|
import { FeatureFlags, USE_ENTITLEMENTS_V2_ENDPOINT_FF } from '@frontegg/rest-api';
|
|
3
|
-
import {
|
|
2
|
+
import { useAuthUserOrNull } from './hooks';
|
|
4
3
|
import { useMemo } from 'react';
|
|
5
4
|
import { useRootState, useShadowDom } from '../common';
|
|
6
5
|
import { useFeatureFlags } from '../flags';
|
|
6
|
+
import { useStore } from '../FronteggStoreContext';
|
|
7
|
+
import { useSnapshot } from 'valtio/react';
|
|
8
|
+
import { getEntitlements, getFeatureEntitlements, getPermissionEntitlements } from '@frontegg/redux-store';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* @returns entitlemenets state as stored in the user
|
|
10
12
|
*/
|
|
11
|
-
const useEntitlementsState = () =>
|
|
12
|
-
user
|
|
13
|
-
|
|
13
|
+
const useEntitlementsState = () => {
|
|
14
|
+
var _useSnapshot$user$ent, _useSnapshot$user;
|
|
15
|
+
const state = useStore().store.auth;
|
|
16
|
+
return (_useSnapshot$user$ent = (_useSnapshot$user = useSnapshot(state).user) == null ? void 0 : _useSnapshot$user.entitlements) != null ? _useSnapshot$user$ent : {};
|
|
17
|
+
};
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* @returns user state
|
|
17
21
|
*/
|
|
18
|
-
const useUserState = () =>
|
|
19
|
-
|
|
20
|
-
}
|
|
22
|
+
const useUserState = () => {
|
|
23
|
+
return useAuthUserOrNull() || undefined;
|
|
24
|
+
};
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
27
|
* @param customAttributes user attributes
|
|
@@ -42,10 +46,10 @@ const useEntitlementsQueryData = customAttributes => {
|
|
|
42
46
|
};
|
|
43
47
|
|
|
44
48
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*/
|
|
49
|
+
@param key feature key
|
|
50
|
+
@param customAttributes user attributes
|
|
51
|
+
@returns if the user is entitled to the given feature and attributes. Attaching the justification if not
|
|
52
|
+
*/
|
|
49
53
|
export const useFeatureEntitlements = (key, customAttributes) => {
|
|
50
54
|
const {
|
|
51
55
|
entitlements,
|
|
@@ -56,10 +60,10 @@ export const useFeatureEntitlements = (key, customAttributes) => {
|
|
|
56
60
|
};
|
|
57
61
|
|
|
58
62
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*/
|
|
63
|
+
@param key permission key
|
|
64
|
+
@param customAttributes user attributes
|
|
65
|
+
@returns if the user is entitled to the given permission and attributes. Attaching the justification if not
|
|
66
|
+
*/
|
|
63
67
|
export const usePermissionEntitlements = (key, customAttributes) => {
|
|
64
68
|
const {
|
|
65
69
|
entitlements,
|
|
@@ -70,10 +74,10 @@ export const usePermissionEntitlements = (key, customAttributes) => {
|
|
|
70
74
|
};
|
|
71
75
|
|
|
72
76
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
*/
|
|
77
|
+
@param entitledToOptions including permission or feature key
|
|
78
|
+
@param customAttributes user attributes
|
|
79
|
+
@returns if the user is entitled to the given feature or permission and attributes (check only one). Attaching the justification if not
|
|
80
|
+
*/
|
|
77
81
|
export const useEntitlements = (options, customAttributes) => {
|
|
78
82
|
const {
|
|
79
83
|
entitlements,
|
|
@@ -108,7 +112,7 @@ export const useEntitlementsActions = () => {
|
|
|
108
112
|
|
|
109
113
|
/**
|
|
110
114
|
@returns if the option to use entitlements is enabled
|
|
111
|
-
|
|
115
|
+
*/
|
|
112
116
|
export const useEntitlementsOptions = () => {
|
|
113
117
|
var _entitlementsOptions$;
|
|
114
118
|
const {
|
package/auth/forgotPassword.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { ForgotPasswordState, ForgotPasswordActions } from '@frontegg/redux-store';
|
|
2
|
-
export declare type ForgotPasswordStateMapper<S> = (state: ForgotPasswordState) => S;
|
|
3
2
|
export declare function useForgotPasswordState(): ForgotPasswordState;
|
|
4
|
-
export declare function useForgotPasswordState<S>(stateMapper: ForgotPasswordStateMapper<S>): S;
|
|
5
3
|
export declare const useForgotPasswordActions: () => ForgotPasswordActions;
|
package/auth/forgotPassword.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return
|
|
1
|
+
import { useStore } from '../FronteggStoreContext';
|
|
2
|
+
import { useSnapshot } from 'valtio/react';
|
|
3
|
+
export function useForgotPasswordState() {
|
|
4
|
+
const state = useStore().store.auth.forgotPasswordState;
|
|
5
|
+
return useSnapshot(state);
|
|
6
6
|
}
|
|
7
|
-
export const useForgotPasswordActions = () =>
|
|
7
|
+
export const useForgotPasswordActions = () => {
|
|
8
|
+
return useStore().stateActions.auth.forgotPasswordActions;
|
|
9
|
+
};
|
package/auth/groups.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { GroupsState, GroupsActions, GroupsDialogsState, GroupsDialogsActions } from '@frontegg/redux-store';
|
|
2
|
-
export declare type GroupsStateMapper<S> = (state: GroupsState) => S;
|
|
3
2
|
export declare function useGroupsState(): GroupsState;
|
|
4
|
-
export declare function useGroupsState<S>(stateMapper: GroupsStateMapper<S>): S;
|
|
5
3
|
export declare const useGroupsActions: () => GroupsActions;
|
|
6
|
-
export declare type GroupsDialogsStateMapper<S> = (state: GroupsDialogsState) => S;
|
|
7
4
|
export declare function useGroupsDialogsState(): GroupsDialogsState;
|
|
8
|
-
export declare function useGroupsDialogsState<S>(stateMapper: GroupsDialogsStateMapper<S>): S;
|
|
9
5
|
export declare const useGroupsDialogsActions: () => GroupsDialogsActions;
|
package/auth/groups.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return stateHookGenerator(stateMapper, 'groupsState');
|
|
1
|
+
import { useStore } from '../FronteggStoreContext';
|
|
2
|
+
import { useSnapshot } from 'valtio/react';
|
|
3
|
+
export function useGroupsState() {
|
|
4
|
+
return useSnapshot(useStore().store.auth.groupsState);
|
|
6
5
|
}
|
|
7
|
-
export const useGroupsActions = () =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export function useGroupsDialogsState(stateMapper = defaultDialogsMapper) {
|
|
13
|
-
return stateHookGenerator(stateMapper, 'groupsDialogsState');
|
|
6
|
+
export const useGroupsActions = () => {
|
|
7
|
+
return useStore().stateActions.auth.groupsActions;
|
|
8
|
+
};
|
|
9
|
+
export function useGroupsDialogsState() {
|
|
10
|
+
return useSnapshot(useStore().store.auth.groupsDialogsState);
|
|
14
11
|
}
|
|
15
|
-
export const useGroupsDialogsActions = () =>
|
|
12
|
+
export const useGroupsDialogsActions = () => {
|
|
13
|
+
return useStore().stateActions.auth.groupsDialogsActions;
|
|
14
|
+
};
|
package/auth/hooks.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AuthActions, AuthPageRoutes, AuthState, User } from '@frontegg/redux-store';
|
|
1
|
+
import { AuthActions, AuthState } from '@frontegg/redux-store';
|
|
3
2
|
import { RedirectOptions } from '@frontegg/rest-api';
|
|
3
|
+
import { AuthPageRoutes, User } from '@frontegg/redux-store';
|
|
4
4
|
export declare type AuthMapper = {
|
|
5
5
|
state: (state: AuthState) => any;
|
|
6
6
|
actions: (actions: AuthActions) => any;
|
|
7
7
|
};
|
|
8
|
-
export declare type StateHookFunction<T> = (() => T) & (<S extends {}>(mapper: (state: T) => S) => S);
|
|
9
8
|
export declare type AuthStateMapper<S> = (state: AuthState) => S;
|
|
10
9
|
/**
|
|
11
10
|
* Use this `frontegg` hook function to obtain the complete authentication state, if it exists.
|
|
@@ -48,8 +47,13 @@ export declare function useAuth<S>(stateMapper: AuthStateMapper<S>): S;
|
|
|
48
47
|
*
|
|
49
48
|
* When using this option, you can have the user on the first load, and you can control when the user is redirected to the login page by using `loginWithRedirect`.
|
|
50
49
|
*/
|
|
51
|
-
export declare const useLoginWithRedirect: () =>
|
|
52
|
-
export declare const useLoginWithRedirectV2: () =>
|
|
50
|
+
export declare const useLoginWithRedirect: () => (additionalParams?: Record<string, string> | undefined) => Promise<void>;
|
|
51
|
+
export declare const useLoginWithRedirectV2: () => (payload?: {
|
|
52
|
+
additionalParams?: Record<string, string> | undefined;
|
|
53
|
+
shouldRedirectToLogin?: boolean | undefined;
|
|
54
|
+
firstTime?: boolean | undefined;
|
|
55
|
+
loginDirectAction?: import("@frontegg/redux-store").LoginDirectAction | undefined;
|
|
56
|
+
} | undefined) => Promise<void>;
|
|
53
57
|
export declare const useAuthActions: () => AuthActions;
|
|
54
58
|
export declare const useOnRedirectTo: () => (path: string, opts?: RedirectOptions | undefined) => void;
|
|
55
59
|
export declare const useAuthRoutes: () => AuthPageRoutes;
|
|
@@ -87,9 +91,3 @@ export declare const useAuthUser: () => User;
|
|
|
87
91
|
* Use this `frontegg` hook function to retrieve the authenticated user. If the user is not authenticated, this hook will return null. To redirect the user to the login page in case they are not authenticated, use the `useAuthUser` method.
|
|
88
92
|
*/
|
|
89
93
|
export declare const useAuthUserOrNull: () => User | null;
|
|
90
|
-
/**
|
|
91
|
-
* hooks helpers
|
|
92
|
-
*/
|
|
93
|
-
export declare const sliceReducerActionsBy: <T extends SliceCaseReducers<any>>(reducer: T) => CaseReducerActions<T>;
|
|
94
|
-
export declare const stateHookGenerator: (stateMapper: any, subState: keyof AuthState, enableMapperFalsyReturnValue?: boolean) => any;
|
|
95
|
-
export declare const reducerActionsGenerator: (actions: any, reducers: SliceCaseReducers<any>) => any;
|
package/auth/hooks.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import { useContext
|
|
3
|
-
import { bindActionCreators } from '@frontegg/redux-store';
|
|
4
|
-
import { authActions, authStoreName } from '@frontegg/redux-store';
|
|
5
|
-
import { shallowEqual } from 'react-redux';
|
|
6
|
-
import { useSelector, useDispatch } from '../FronteggStoreContext';
|
|
2
|
+
import { useContext } from 'react';
|
|
7
3
|
import { ContextHolder } from '@frontegg/rest-api';
|
|
8
|
-
import {
|
|
4
|
+
import { FronteggStoreContext, useStore } from '../FronteggStoreContext';
|
|
5
|
+
import { useSnapshot } from 'valtio/react';
|
|
9
6
|
const defaultMapper = {
|
|
10
7
|
state: state => state,
|
|
11
8
|
actions: actions => actions
|
|
@@ -26,7 +23,9 @@ const defaultMapper = {
|
|
|
26
23
|
*/
|
|
27
24
|
|
|
28
25
|
export function useAuth(stateMapper = defaultMapper.state) {
|
|
29
|
-
|
|
26
|
+
const state = useStore().store.auth;
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
return stateMapper(useSnapshot(state));
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
/**
|
|
@@ -56,21 +55,25 @@ export function useAuth(stateMapper = defaultMapper.state) {
|
|
|
56
55
|
* When using this option, you can have the user on the first load, and you can control when the user is redirected to the login page by using `loginWithRedirect`.
|
|
57
56
|
*/
|
|
58
57
|
export const useLoginWithRedirect = () => {
|
|
59
|
-
const
|
|
60
|
-
|
|
58
|
+
const {
|
|
59
|
+
actions
|
|
60
|
+
} = useContext(FronteggStoreContext);
|
|
61
|
+
return actions.requestHostedLoginAuthorize;
|
|
61
62
|
};
|
|
62
63
|
export const useLoginWithRedirectV2 = () => {
|
|
63
|
-
const
|
|
64
|
-
|
|
64
|
+
const {
|
|
65
|
+
actions
|
|
66
|
+
} = useContext(FronteggStoreContext);
|
|
67
|
+
return actions.requestHostedLoginAuthorizeV2;
|
|
65
68
|
};
|
|
66
69
|
export const useAuthActions = () => {
|
|
67
|
-
|
|
68
|
-
return useMemo(() => bindActionCreators(authActions, dispatch), [authActions]);
|
|
70
|
+
return useStore().actions;
|
|
69
71
|
};
|
|
70
72
|
export const useOnRedirectTo = () => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
const {
|
|
74
|
+
onRedirectTo
|
|
75
|
+
} = useAuth();
|
|
76
|
+
return onRedirectTo != null ? onRedirectTo : ContextHolder.onRedirectTo;
|
|
74
77
|
};
|
|
75
78
|
export const useAuthRoutes = () => useAuth(state => _extends({}, state.routes));
|
|
76
79
|
|
|
@@ -84,11 +87,14 @@ export const useAuthRoutes = () => useAuth(state => _extends({}, state.routes));
|
|
|
84
87
|
*
|
|
85
88
|
* use this frontegg hook function to get if user is "Authenticated"
|
|
86
89
|
*/
|
|
87
|
-
export const useIsAuthenticated = () =>
|
|
88
|
-
|
|
90
|
+
export const useIsAuthenticated = () => {
|
|
91
|
+
const {
|
|
89
92
|
isAuthenticated
|
|
90
|
-
}
|
|
91
|
-
|
|
93
|
+
} = useAuth(state => ({
|
|
94
|
+
isAuthenticated: state.isAuthenticated
|
|
95
|
+
}));
|
|
96
|
+
return isAuthenticated;
|
|
97
|
+
};
|
|
92
98
|
|
|
93
99
|
/**
|
|
94
100
|
* ```jsx
|
|
@@ -132,43 +138,6 @@ export const useAuthUser = () => {
|
|
|
132
138
|
export const useAuthUserOrNull = () => {
|
|
133
139
|
const {
|
|
134
140
|
user
|
|
135
|
-
} =
|
|
136
|
-
[authStoreName]: {
|
|
137
|
-
user
|
|
138
|
-
}
|
|
139
|
-
}) => ({
|
|
140
|
-
user
|
|
141
|
-
}), shallowEqual);
|
|
141
|
+
} = useAuth();
|
|
142
142
|
return user || null;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* hooks helpers
|
|
147
|
-
*/
|
|
148
|
-
export const sliceReducerActionsBy = reducer => {
|
|
149
|
-
const reducerKeys = Object.keys(reducer);
|
|
150
|
-
const reducerActions = reducerKeys.map(key => ({
|
|
151
|
-
[key]: authActions[key]
|
|
152
|
-
}));
|
|
153
|
-
return reducerActions.reduce((p, n) => _extends({}, p, n), {});
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/*
|
|
157
|
-
* enableMapperFalsyReturnValue was added to be backward compatible with all usages
|
|
158
|
-
* the scenario that require enableMapperFalsyReturnValue of true is when the
|
|
159
|
-
* mapper function returns a falsy value then we want to return it as is - it's a valid case like in entitlements (when it's undefined)
|
|
160
|
-
* IMO all usages should be like that
|
|
161
|
-
*/
|
|
162
|
-
export const stateHookGenerator = (stateMapper, subState, enableMapperFalsyReturnValue = false) => {
|
|
163
|
-
return useSelector(state => {
|
|
164
|
-
const mapperValue = stateMapper == null ? void 0 : stateMapper(state[authStoreName][subState]);
|
|
165
|
-
if (enableMapperFalsyReturnValue && stateMapper) {
|
|
166
|
-
return mapperValue;
|
|
167
|
-
}
|
|
168
|
-
return mapperValue != null ? mapperValue : state[authStoreName][subState];
|
|
169
|
-
}, shallowEqual);
|
|
170
|
-
};
|
|
171
|
-
export const reducerActionsGenerator = (actions, reducers) => {
|
|
172
|
-
const dispatch = useDispatch();
|
|
173
|
-
return useMemo(() => bindActionCreators(_extends({}, actions, sliceReducerActionsBy(reducers)), dispatch), [dispatch]);
|
|
174
143
|
};
|
package/auth/impersonate.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { ImpersonateState, ImpersonateActions } from '@frontegg/redux-store';
|
|
2
|
-
export declare type ImpersonateStateMapper<S> = (state: ImpersonateState) => S;
|
|
3
2
|
export declare function useImpersonateState(): ImpersonateState;
|
|
4
|
-
export declare function useImpersonateState<S>(stateMapper: ImpersonateStateMapper<S>): S;
|
|
5
3
|
export declare const useImpersonateActions: () => ImpersonateActions;
|
package/auth/impersonate.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return stateHookGenerator(stateMapper, 'impersonateState');
|
|
1
|
+
import { useSnapshot } from 'valtio/react';
|
|
2
|
+
import { useStore } from '../FronteggStoreContext';
|
|
3
|
+
export function useImpersonateState() {
|
|
4
|
+
return useSnapshot(useStore().store.auth.impersonateState);
|
|
6
5
|
}
|
|
7
|
-
export const useImpersonateActions = () =>
|
|
6
|
+
export const useImpersonateActions = () => {
|
|
7
|
+
return useStore().stateActions.auth.impersonateActions;
|
|
8
|
+
};
|
package/auth/index.d.ts
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
export { useAuth, useAuthActions, useOnRedirectTo, useAuthRoutes, useIsAuthenticated, useAuthUser, useAuthUserOrNull, useLoginWithRedirect, useLoginWithRedirectV2, } from './hooks';
|
|
2
2
|
export * from './acceptInvitation';
|
|
3
3
|
export * from './activateAccount';
|
|
4
|
+
export * from './allAccounts';
|
|
4
5
|
export * from './apiTokens';
|
|
6
|
+
export * from './customLogin';
|
|
7
|
+
export * from './entitlements';
|
|
5
8
|
export * from './forgotPassword';
|
|
6
|
-
export * from './
|
|
9
|
+
export * from './groups';
|
|
10
|
+
export * from './impersonate';
|
|
7
11
|
export * from './login';
|
|
8
|
-
export * from './stepUp';
|
|
9
12
|
export * from './mfa';
|
|
13
|
+
export * from './passkeys';
|
|
10
14
|
export * from './profile';
|
|
15
|
+
export * from './provisioning';
|
|
16
|
+
export * from './resetPhoneNumber';
|
|
17
|
+
export * from './roles';
|
|
18
|
+
export * from './sessions';
|
|
11
19
|
export * from './signup';
|
|
20
|
+
export * from './sms';
|
|
12
21
|
export * from './socialLogin';
|
|
13
|
-
export * from './team';
|
|
14
22
|
export * from './sso';
|
|
15
|
-
export * from './
|
|
23
|
+
export * from './stepUp';
|
|
24
|
+
export * from './team';
|
|
25
|
+
export * from './security';
|
|
16
26
|
export * from './tenants';
|
|
17
|
-
export * from './roles';
|
|
18
|
-
export * from './sessions';
|
|
19
|
-
export * from './security/sessionsPolicy';
|
|
20
|
-
export * from './security/restrictions';
|
|
21
|
-
export * from './provisioning';
|
|
22
|
-
export * from './impersonate';
|
|
23
|
-
export * from './passkeys';
|
|
24
|
-
export * from './groups';
|
|
25
|
-
export * from './customLogin';
|
|
26
|
-
export * from './MSP/allAccounts';
|
|
27
|
-
export * from './entitlements';
|
|
28
|
-
export * from './security/securityCenter';
|
|
29
|
-
export * from './sms';
|
package/auth/index.js
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
export { useAuth, useAuthActions, useOnRedirectTo, useAuthRoutes, useIsAuthenticated, useAuthUser, useAuthUserOrNull, useLoginWithRedirect, useLoginWithRedirectV2 } from './hooks';
|
|
2
2
|
export * from './acceptInvitation';
|
|
3
3
|
export * from './activateAccount';
|
|
4
|
+
export * from './allAccounts';
|
|
4
5
|
export * from './apiTokens';
|
|
6
|
+
export * from './customLogin';
|
|
7
|
+
export * from './entitlements';
|
|
5
8
|
export * from './forgotPassword';
|
|
6
|
-
export * from './
|
|
9
|
+
export * from './groups';
|
|
10
|
+
export * from './impersonate';
|
|
7
11
|
export * from './login';
|
|
8
|
-
export * from './stepUp';
|
|
9
12
|
export * from './mfa';
|
|
13
|
+
export * from './passkeys';
|
|
10
14
|
export * from './profile';
|
|
15
|
+
export * from './provisioning';
|
|
16
|
+
export * from './resetPhoneNumber';
|
|
17
|
+
export * from './roles';
|
|
18
|
+
export * from './sessions';
|
|
11
19
|
export * from './signup';
|
|
20
|
+
export * from './sms';
|
|
12
21
|
export * from './socialLogin';
|
|
13
|
-
export * from './team';
|
|
14
22
|
export * from './sso';
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './
|
|
18
|
-
export * from './
|
|
19
|
-
export * from './security/sessionsPolicy';
|
|
20
|
-
export * from './security/restrictions';
|
|
21
|
-
export * from './provisioning';
|
|
22
|
-
export * from './impersonate';
|
|
23
|
-
export * from './passkeys';
|
|
24
|
-
export * from './groups';
|
|
25
|
-
export * from './customLogin';
|
|
26
|
-
export * from './MSP/allAccounts';
|
|
27
|
-
export * from './entitlements';
|
|
28
|
-
export * from './security/securityCenter';
|
|
29
|
-
export * from './sms';
|
|
23
|
+
export * from './stepUp';
|
|
24
|
+
export * from './team';
|
|
25
|
+
export * from './security';
|
|
26
|
+
export * from './tenants';
|
package/auth/login.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoginState, LoginActions } from '@frontegg/redux-store';
|
|
1
|
+
import type { LoginState, LoginActions } from '@frontegg/redux-store';
|
|
2
2
|
export declare type LoginStateMapper<S> = (state: LoginState) => S;
|
|
3
3
|
export declare function useLoginState(): LoginState;
|
|
4
4
|
export declare function useLoginState<S>(stateMapper: LoginStateMapper<S>): S;
|
package/auth/login.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useSnapshot } from 'valtio/react';
|
|
2
|
+
import { useStore } from '../FronteggStoreContext';
|
|
3
|
+
|
|
4
|
+
// TODO: remove useless stateMapper, valtio already does this
|
|
5
|
+
|
|
3
6
|
const defaultMapper = state => state;
|
|
7
|
+
// @deprecated use useLoginState() instead
|
|
4
8
|
export function useLoginState(stateMapper = defaultMapper) {
|
|
5
|
-
|
|
9
|
+
const {
|
|
10
|
+
loginState
|
|
11
|
+
} = useStore().store.auth;
|
|
12
|
+
return stateMapper(useSnapshot(loginState));
|
|
6
13
|
}
|
|
7
|
-
export const useLoginActions = () =>
|
|
14
|
+
export const useLoginActions = () => {
|
|
15
|
+
return useStore().stateActions.auth.loginActions;
|
|
16
|
+
};
|
package/auth/mfa.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MfaActions, MFAState } from '@frontegg/redux-store';
|
|
1
|
+
import type { MfaActions, MFAState } from '@frontegg/redux-store';
|
|
2
2
|
declare type AuthMfaStateMapper<S> = (state: MFAState) => S;
|
|
3
3
|
export declare function useMfaState(): MFAState;
|
|
4
4
|
export declare function useMfaState<S>(stateMapper: AuthMfaStateMapper<S>): S;
|
package/auth/mfa.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useSnapshot } from 'valtio/react';
|
|
2
|
+
import { useStore } from '../FronteggStoreContext';
|
|
3
|
+
|
|
4
|
+
// TODO: remove useless stateMapper, valtio already does this
|
|
5
|
+
|
|
3
6
|
const defaultMapper = state => state;
|
|
7
|
+
// @deprecated use useMfaState() instead
|
|
4
8
|
export function useMfaState(stateMapper = defaultMapper) {
|
|
5
|
-
|
|
9
|
+
const {
|
|
10
|
+
mfaState
|
|
11
|
+
} = useStore().store.auth;
|
|
12
|
+
return stateMapper(useSnapshot(mfaState));
|
|
6
13
|
}
|
|
7
|
-
export const useMfaActions = () =>
|
|
14
|
+
export const useMfaActions = () => {
|
|
15
|
+
return useStore().stateActions.auth.mfaActions;
|
|
16
|
+
};
|
package/auth/passkeys.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { PasskeysActions, PasskeysState } from '@frontegg/redux-store';
|
|
2
|
-
declare type AuthPasskeysStateMapper<S> = (state: PasskeysState) => S;
|
|
1
|
+
import type { PasskeysActions, PasskeysState } from '@frontegg/redux-store';
|
|
3
2
|
export declare function usePasskeysState(): PasskeysState;
|
|
4
|
-
export declare function usePasskeysState<S>(stateMapper: AuthPasskeysStateMapper<S>): S;
|
|
5
3
|
export declare const usePasskeysActions: () => PasskeysActions;
|
|
6
|
-
export {};
|
package/auth/passkeys.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return stateHookGenerator(stateMapper, 'passkeysState');
|
|
1
|
+
import { useSnapshot } from 'valtio/react';
|
|
2
|
+
import { useStore } from '../FronteggStoreContext';
|
|
3
|
+
export function usePasskeysState() {
|
|
4
|
+
return useSnapshot(useStore().store.auth.passkeysState);
|
|
6
5
|
}
|
|
7
|
-
export const usePasskeysActions = () =>
|
|
6
|
+
export const usePasskeysActions = () => {
|
|
7
|
+
return useStore().stateActions.auth.passkeysActions;
|
|
8
|
+
};
|
package/auth/profile.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { ProfileActions, ProfileState } from '@frontegg/redux-store';
|
|
2
|
-
export declare const reloadProfileIfNeeded: () => void;
|
|
3
|
-
export declare type ProfileStateMapper<S> = (state: ProfileState) => S;
|
|
1
|
+
import type { ProfileActions, ProfileState } from '@frontegg/redux-store';
|
|
4
2
|
export declare function useProfileState(): ProfileState;
|
|
5
|
-
export declare function useProfileState<S>(stateMapper: ProfileStateMapper<S>): S;
|
|
6
3
|
export declare const useProfileActions: () => ProfileActions;
|
|
4
|
+
export declare const reloadProfileIfNeeded: () => void;
|
package/auth/profile.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useSnapshot } from 'valtio/react';
|
|
3
|
+
import { useStore } from '../FronteggStoreContext';
|
|
4
|
+
export function useProfileState() {
|
|
5
|
+
return useSnapshot(useStore().store.auth.profileState);
|
|
6
|
+
}
|
|
7
|
+
export const useProfileActions = () => {
|
|
8
|
+
return useStore().stateActions.auth.profileActions;
|
|
9
|
+
};
|
|
4
10
|
export const reloadProfileIfNeeded = () => {
|
|
5
11
|
const {
|
|
6
12
|
loading
|
|
@@ -11,9 +17,4 @@ export const reloadProfileIfNeeded = () => {
|
|
|
11
17
|
useEffect(() => {
|
|
12
18
|
!loading && loadProfile();
|
|
13
19
|
}, []);
|
|
14
|
-
};
|
|
15
|
-
const defaultMapper = state => state;
|
|
16
|
-
export function useProfileState(stateMapper = defaultMapper) {
|
|
17
|
-
return stateHookGenerator(stateMapper, 'profileState');
|
|
18
|
-
}
|
|
19
|
-
export const useProfileActions = () => reducerActionsGenerator(profileActions, profileReducers);
|
|
20
|
+
};
|
package/auth/provisioning.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ProvisioningActions, ProvisioningState } from '@frontegg/redux-store';
|
|
2
|
-
export declare type ProvisioningStateMapper<S> = (state: ProvisioningState) => S;
|
|
1
|
+
import type { ProvisioningActions, ProvisioningState } from '@frontegg/redux-store';
|
|
3
2
|
export declare function useProvisioningState(): ProvisioningState;
|
|
4
|
-
export declare function useProvisioningState<S>(stateMapper: ProvisioningStateMapper<S>): S;
|
|
5
3
|
export declare const useProvisioningActions: () => ProvisioningActions;
|
package/auth/provisioning.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return stateHookGenerator(stateMapper, 'provisioningState');
|
|
1
|
+
import { useSnapshot } from 'valtio/react';
|
|
2
|
+
import { useStore } from '../FronteggStoreContext';
|
|
3
|
+
export function useProvisioningState() {
|
|
4
|
+
return useSnapshot(useStore().store.auth.provisioningState);
|
|
6
5
|
}
|
|
7
|
-
export const useProvisioningActions = () =>
|
|
6
|
+
export const useProvisioningActions = () => {
|
|
7
|
+
return useStore().stateActions.auth.provisioningActions;
|
|
8
|
+
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ResetPhoneNumberState, ResetPhoneNumberActions } from '@frontegg/redux-store';
|
|
2
|
-
export declare type ResetPhoneNumberStateMapper<S> = (state: ResetPhoneNumberState) => S;
|
|
1
|
+
import type { ResetPhoneNumberState, ResetPhoneNumberActions } from '@frontegg/redux-store';
|
|
3
2
|
export declare function useResetPhoneNumberState(): ResetPhoneNumberState;
|
|
4
|
-
export declare function useResetPhoneNumberState<S>(stateMapper: ResetPhoneNumberStateMapper<S>): S;
|
|
5
3
|
export declare const useResetPhoneNumberActions: () => ResetPhoneNumberActions;
|