@stytch/react 19.6.0 → 19.7.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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +29 -4
- package/dist/index.esm.d.ts +29 -4
- package/dist/index.esm.js +89 -5
- package/dist/index.js +88 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @stytch/react
|
|
2
2
|
|
|
3
|
+
## 19.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 14f8002: Add in Hook and HOC for accessing user roles
|
|
8
|
+
|
|
9
|
+
## 19.6.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 8a32b3f: Fix an issue with localization in the PasswordError component when using custom password strength rules
|
|
14
|
+
|
|
3
15
|
## 19.6.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
|
-
import { StytchProjectConfigurationInput, StytchUIClient, Callbacks, StringsOptions, StytchLoginConfig, StyleConfig } from "@stytch/vanilla-js";
|
|
4
|
+
import { StytchProjectConfigurationInput, StytchUIClient, Callbacks, StringsOptions, StytchLoginConfig, StyleConfig, IDPConsentScreenManifest } from "@stytch/vanilla-js";
|
|
5
5
|
import { StytchHeadlessClient } from "@stytch/vanilla-js/headless";
|
|
6
6
|
import { Session as Session$0 } from "@stytch/vanilla-js/headless";
|
|
7
7
|
import { User as User$0 } from "@stytch/vanilla-js/headless";
|
|
@@ -123,7 +123,16 @@ interface StytchResetPasswordProps<TProjectConfiguration extends StytchProjectCo
|
|
|
123
123
|
*/
|
|
124
124
|
passwordResetToken: string;
|
|
125
125
|
}
|
|
126
|
-
type
|
|
126
|
+
type IDPConsentScreenManifestGenerator = (input: {
|
|
127
|
+
scopes: string[];
|
|
128
|
+
clientName: string;
|
|
129
|
+
}) => IDPConsentScreenManifest;
|
|
130
|
+
type IdentityProviderProps = Omit<StytchProps, "config"> & {
|
|
131
|
+
/**
|
|
132
|
+
* Optional {@link IDPConsentScreenManifestGenerator} to customize the consent screen.
|
|
133
|
+
*/
|
|
134
|
+
getIDPConsentManifest?: IDPConsentScreenManifestGenerator;
|
|
135
|
+
};
|
|
127
136
|
/**
|
|
128
137
|
* The Stytch Reset Password component.
|
|
129
138
|
* This component can only be used with a Stytch UI Client
|
|
@@ -208,7 +217,7 @@ declare const StytchPasskeyRegistration: <TProjectConfiguration extends Partial<
|
|
|
208
217
|
* }}
|
|
209
218
|
* />
|
|
210
219
|
*/
|
|
211
|
-
declare const IdentityProvider: ({ styles, callbacks, strings }: IdentityProviderProps) => React.JSX.Element;
|
|
220
|
+
declare const IdentityProvider: ({ styles, callbacks, strings, getIDPConsentManifest }: IdentityProviderProps) => React.JSX.Element;
|
|
212
221
|
/**
|
|
213
222
|
* Returns the active User.
|
|
214
223
|
* The Stytch SDKs are used for client-side authentication and session management.
|
|
@@ -273,6 +282,22 @@ declare const withStytchSession$0: <T extends object, TAssumeHydrated extends bo
|
|
|
273
282
|
stytchSessionIsInitialized: boolean;
|
|
274
283
|
stytchSessionIsFromCache: boolean;
|
|
275
284
|
}>) => React.ComponentType<T>;
|
|
285
|
+
declare const useStytchIsAuthorized$0: <TAssumeHydrated extends boolean = true>(resourceId: string, action: string) => TAssumeHydrated extends true ? {
|
|
286
|
+
isAuthorized: boolean;
|
|
287
|
+
fromCache: boolean;
|
|
288
|
+
isInitialized: boolean;
|
|
289
|
+
} : {
|
|
290
|
+
isAuthorized: false;
|
|
291
|
+
fromCache: false;
|
|
292
|
+
isInitialized: false;
|
|
293
|
+
} | {
|
|
294
|
+
isAuthorized: boolean;
|
|
295
|
+
fromCache: boolean;
|
|
296
|
+
isInitialized: boolean;
|
|
297
|
+
};
|
|
298
|
+
declare const withStytchPermissions$0: <Permissions_1 extends Record<string, string>, T extends object>(Component: React.ComponentType<T & {
|
|
299
|
+
stytchPermissions: Record<string, Record<string, boolean>>;
|
|
300
|
+
}>) => React.ComponentType<T>;
|
|
276
301
|
/**
|
|
277
302
|
* The Stytch Client object passed in to <StytchProvider /> in your application root.
|
|
278
303
|
* Either a StytchUIClient or StytchHeadlessClient.
|
|
@@ -316,5 +341,5 @@ interface StytchProviderProps$0<TProjectConfiguration extends StytchProjectConfi
|
|
|
316
341
|
* )
|
|
317
342
|
*/
|
|
318
343
|
declare const StytchProvider$0: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>({ stytch, children, assumeHydrated }: StytchProviderProps$0<TProjectConfiguration>) => JSX.Element;
|
|
319
|
-
export { StytchLogin, StytchPasswordReset, StytchPasskeyRegistration, IdentityProvider, StytchProvider$0 as StytchProvider, useStytch, useStytchSession$0 as useStytchSession, useStytchUser$0 as useStytchUser, withStytch, withStytchSession$0 as withStytchSession, withStytchUser$0 as withStytchUser };
|
|
344
|
+
export { StytchLogin, StytchPasswordReset, StytchPasskeyRegistration, IdentityProvider, StytchProvider$0 as StytchProvider, useStytch, useStytchSession$0 as useStytchSession, useStytchUser$0 as useStytchUser, withStytch, withStytchSession$0 as withStytchSession, withStytchUser$0 as withStytchUser, useStytchIsAuthorized$0 as useStytchIsAuthorized, withStytchPermissions$0 as withStytchPermissions };
|
|
320
345
|
export type { StytchProviderProps$0 as StytchProviderProps, StytchProps, StytchResetPasswordProps, IdentityProviderProps };
|
package/dist/index.esm.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
|
-
import { StytchProjectConfigurationInput, StytchUIClient, Callbacks, StringsOptions, StytchLoginConfig, StyleConfig } from "@stytch/vanilla-js";
|
|
4
|
+
import { StytchProjectConfigurationInput, StytchUIClient, Callbacks, StringsOptions, StytchLoginConfig, StyleConfig, IDPConsentScreenManifest } from "@stytch/vanilla-js";
|
|
5
5
|
import { StytchHeadlessClient } from "@stytch/vanilla-js/headless";
|
|
6
6
|
import { Session as Session$0 } from "@stytch/vanilla-js/headless";
|
|
7
7
|
import { User as User$0 } from "@stytch/vanilla-js/headless";
|
|
@@ -123,7 +123,16 @@ interface StytchResetPasswordProps<TProjectConfiguration extends StytchProjectCo
|
|
|
123
123
|
*/
|
|
124
124
|
passwordResetToken: string;
|
|
125
125
|
}
|
|
126
|
-
type
|
|
126
|
+
type IDPConsentScreenManifestGenerator = (input: {
|
|
127
|
+
scopes: string[];
|
|
128
|
+
clientName: string;
|
|
129
|
+
}) => IDPConsentScreenManifest;
|
|
130
|
+
type IdentityProviderProps = Omit<StytchProps, "config"> & {
|
|
131
|
+
/**
|
|
132
|
+
* Optional {@link IDPConsentScreenManifestGenerator} to customize the consent screen.
|
|
133
|
+
*/
|
|
134
|
+
getIDPConsentManifest?: IDPConsentScreenManifestGenerator;
|
|
135
|
+
};
|
|
127
136
|
/**
|
|
128
137
|
* The Stytch Reset Password component.
|
|
129
138
|
* This component can only be used with a Stytch UI Client
|
|
@@ -208,7 +217,7 @@ declare const StytchPasskeyRegistration: <TProjectConfiguration extends Partial<
|
|
|
208
217
|
* }}
|
|
209
218
|
* />
|
|
210
219
|
*/
|
|
211
|
-
declare const IdentityProvider: ({ styles, callbacks, strings }: IdentityProviderProps) => React.JSX.Element;
|
|
220
|
+
declare const IdentityProvider: ({ styles, callbacks, strings, getIDPConsentManifest }: IdentityProviderProps) => React.JSX.Element;
|
|
212
221
|
/**
|
|
213
222
|
* Returns the active User.
|
|
214
223
|
* The Stytch SDKs are used for client-side authentication and session management.
|
|
@@ -273,6 +282,22 @@ declare const withStytchSession$0: <T extends object, TAssumeHydrated extends bo
|
|
|
273
282
|
stytchSessionIsInitialized: boolean;
|
|
274
283
|
stytchSessionIsFromCache: boolean;
|
|
275
284
|
}>) => React.ComponentType<T>;
|
|
285
|
+
declare const useStytchIsAuthorized$0: <TAssumeHydrated extends boolean = true>(resourceId: string, action: string) => TAssumeHydrated extends true ? {
|
|
286
|
+
isAuthorized: boolean;
|
|
287
|
+
fromCache: boolean;
|
|
288
|
+
isInitialized: boolean;
|
|
289
|
+
} : {
|
|
290
|
+
isAuthorized: false;
|
|
291
|
+
fromCache: false;
|
|
292
|
+
isInitialized: false;
|
|
293
|
+
} | {
|
|
294
|
+
isAuthorized: boolean;
|
|
295
|
+
fromCache: boolean;
|
|
296
|
+
isInitialized: boolean;
|
|
297
|
+
};
|
|
298
|
+
declare const withStytchPermissions$0: <Permissions_1 extends Record<string, string>, T extends object>(Component: React.ComponentType<T & {
|
|
299
|
+
stytchPermissions: Record<string, Record<string, boolean>>;
|
|
300
|
+
}>) => React.ComponentType<T>;
|
|
276
301
|
/**
|
|
277
302
|
* The Stytch Client object passed in to <StytchProvider /> in your application root.
|
|
278
303
|
* Either a StytchUIClient or StytchHeadlessClient.
|
|
@@ -316,5 +341,5 @@ interface StytchProviderProps$0<TProjectConfiguration extends StytchProjectConfi
|
|
|
316
341
|
* )
|
|
317
342
|
*/
|
|
318
343
|
declare const StytchProvider$0: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>({ stytch, children, assumeHydrated }: StytchProviderProps$0<TProjectConfiguration>) => JSX.Element;
|
|
319
|
-
export { StytchLogin, StytchPasswordReset, StytchPasskeyRegistration, IdentityProvider, StytchProvider$0 as StytchProvider, useStytch, useStytchSession$0 as useStytchSession, useStytchUser$0 as useStytchUser, withStytch, withStytchSession$0 as withStytchSession, withStytchUser$0 as withStytchUser };
|
|
344
|
+
export { StytchLogin, StytchPasswordReset, StytchPasskeyRegistration, IdentityProvider, StytchProvider$0 as StytchProvider, useStytch, useStytchSession$0 as useStytchSession, useStytchUser$0 as useStytchUser, withStytch, withStytchSession$0 as withStytchSession, withStytchUser$0 as withStytchUser, useStytchIsAuthorized$0 as useStytchIsAuthorized, withStytchPermissions$0 as withStytchPermissions };
|
|
320
345
|
export type { StytchProviderProps$0 as StytchProviderProps, StytchProps, StytchResetPasswordProps, IdentityProviderProps };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, { createContext, useContext, useMemo, useCallback, useRef
|
|
1
|
+
import React, { createContext, useContext, useEffect, useMemo, useCallback, useRef } from 'react';
|
|
2
2
|
import { i as invariant, u as useAsyncState, m as mergeWithStableProps, a as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect-681e2138.js';
|
|
3
|
-
import { n as noProviderError,
|
|
3
|
+
import { n as noProviderError, i as isStytchSSRProxy, p as providerMustBeUniqueError, a as noHeadlessClientError } from './StytchSSRProxy-34c789b5.js';
|
|
4
4
|
|
|
5
5
|
const initialUser = {
|
|
6
6
|
user: null,
|
|
@@ -95,6 +95,87 @@ const withStytchSession$1 = (Component) => {
|
|
|
95
95
|
WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;
|
|
96
96
|
return WithStytchSession;
|
|
97
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* Determines whether the logged-in user is allowed to perform the specified action on the specified resource.
|
|
100
|
+
* Returns `true` if the user can perform the action, `false` otherwise.
|
|
101
|
+
*
|
|
102
|
+
* If the user is not logged in, this method will always return false.
|
|
103
|
+
* If the resource or action provided are not valid for the configured RBAC policy, this method will return false.
|
|
104
|
+
*
|
|
105
|
+
* Remember - authorization checks for sensitive actions should always occur on the backend as well.
|
|
106
|
+
* @example
|
|
107
|
+
* const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');
|
|
108
|
+
* return <button disabled={!isAuthorized}>Edit</button>
|
|
109
|
+
*/
|
|
110
|
+
const useStytchIsAuthorized$1 = (resourceId, action) => {
|
|
111
|
+
invariant(useIsMounted__INTERNAL(), noProviderError('useStytchIsAuthorized', 'StytchProvider'));
|
|
112
|
+
const client = useStytch();
|
|
113
|
+
const { user } = useStytchUser$1();
|
|
114
|
+
const [isAuthorized, setIsAuthorized] = useAsyncState({
|
|
115
|
+
isInitialized: false,
|
|
116
|
+
fromCache: false,
|
|
117
|
+
isAuthorized: false,
|
|
118
|
+
});
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (isStytchSSRProxy(client)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
setIsAuthorized({
|
|
124
|
+
isInitialized: true,
|
|
125
|
+
fromCache: true,
|
|
126
|
+
isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),
|
|
127
|
+
});
|
|
128
|
+
}, [action, client, resourceId, setIsAuthorized]);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (isStytchSSRProxy(client)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {
|
|
134
|
+
setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });
|
|
135
|
+
});
|
|
136
|
+
}, [client, user === null || user === void 0 ? void 0 : user.roles, resourceId, action, setIsAuthorized]);
|
|
137
|
+
return isAuthorized;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Wrap your component with this HOC in order to receive the permissions for the logged-in user.
|
|
141
|
+
* Evaluates all permissions granted to the logged-in user.
|
|
142
|
+
* Returns a Record<RoleId, Record<Action, boolean>> response indicating the user's permissions.
|
|
143
|
+
* Each boolean will be `true` if the user can perform the action, `false` otherwise.
|
|
144
|
+
*
|
|
145
|
+
* If the user is not logged in, all values will be false.
|
|
146
|
+
*
|
|
147
|
+
* Remember - authorization checks for sensitive actions should always occur on the backend as well.
|
|
148
|
+
* @example
|
|
149
|
+
* type Permissions = {
|
|
150
|
+
* document: 'create' | 'read' | 'write
|
|
151
|
+
* image: 'create' | 'read'
|
|
152
|
+
* }
|
|
153
|
+
*
|
|
154
|
+
* const MyComponent = (props) => {
|
|
155
|
+
* const canEditDocuments = props.stytchPermissions.document.edit;
|
|
156
|
+
* const canReadImages = props.stytchPermissions.image.read;
|
|
157
|
+
* }
|
|
158
|
+
* return withStytchPermissions<Permissions>(MyComponent)
|
|
159
|
+
*/
|
|
160
|
+
const withStytchPermissions$1 = (Component) => {
|
|
161
|
+
const WithStytchPermissions = (props) => {
|
|
162
|
+
invariant(useIsMounted__INTERNAL(), noProviderError('useRBACPermissions', 'StytchProvider'));
|
|
163
|
+
const client = useStytch();
|
|
164
|
+
const { user } = useStytchUser$1();
|
|
165
|
+
const [permissions, setPermissions] = useAsyncState({ loaded: false, value: null });
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
client.rbac.allPermissions().then((permissions) => {
|
|
168
|
+
setPermissions({ loaded: true, value: permissions });
|
|
169
|
+
});
|
|
170
|
+
}, [client, user === null || user === void 0 ? void 0 : user.roles, setPermissions]);
|
|
171
|
+
if (!permissions.loaded) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
return React.createElement(Component, Object.assign({}, props, { stytchPermissions: permissions.value }));
|
|
175
|
+
};
|
|
176
|
+
WithStytchPermissions.displayName = `withStytchPermissions(${Component.displayName || Component.name || 'Component'})`;
|
|
177
|
+
return WithStytchPermissions;
|
|
178
|
+
};
|
|
98
179
|
/**
|
|
99
180
|
* The Stytch Context Provider.
|
|
100
181
|
* Wrap your application with this component in order to use Stytch everywhere in your app.
|
|
@@ -334,7 +415,7 @@ const StytchPasskeyRegistration = ({ config, styles, callbacks, strings, }) => {
|
|
|
334
415
|
* }}
|
|
335
416
|
* />
|
|
336
417
|
*/
|
|
337
|
-
const IdentityProvider = ({ styles, callbacks, strings }) => {
|
|
418
|
+
const IdentityProvider = ({ styles, callbacks, strings, getIDPConsentManifest }) => {
|
|
338
419
|
invariant(useIsMounted__INTERNAL(), noProviderError('<IdentityProvider />'));
|
|
339
420
|
const stytchClient = useStytch();
|
|
340
421
|
const user = useStytchUser$1();
|
|
@@ -355,8 +436,9 @@ const IdentityProvider = ({ styles, callbacks, strings }) => {
|
|
|
355
436
|
elementId: `#${containerEl.current.id}`,
|
|
356
437
|
styles,
|
|
357
438
|
strings,
|
|
439
|
+
getIDPConsentManifest,
|
|
358
440
|
});
|
|
359
|
-
}, [stytchClient, styles, callbacks, user, strings]);
|
|
441
|
+
}, [stytchClient, styles, callbacks, user, strings, getIDPConsentManifest]);
|
|
360
442
|
return React.createElement("div", { ref: containerEl });
|
|
361
443
|
};
|
|
362
444
|
|
|
@@ -392,6 +474,8 @@ const useStytchUser = useStytchUser$1;
|
|
|
392
474
|
const useStytchSession = useStytchSession$1;
|
|
393
475
|
const withStytchUser = withStytchUser$1;
|
|
394
476
|
const withStytchSession = withStytchSession$1;
|
|
477
|
+
const useStytchIsAuthorized = useStytchIsAuthorized$1;
|
|
478
|
+
const withStytchPermissions = withStytchPermissions$1;
|
|
395
479
|
/**
|
|
396
480
|
* The Stytch Context Provider.
|
|
397
481
|
* Wrap your application with this component in order to use Stytch everywhere in your app.
|
|
@@ -409,4 +493,4 @@ const StytchProvider = ({ stytch, children, assumeHydrated = true, }) => {
|
|
|
409
493
|
return (React.createElement(StytchProvider$1, { stytch: stytch, assumeHydrated: assumeHydrated }, children));
|
|
410
494
|
};
|
|
411
495
|
|
|
412
|
-
export { IdentityProvider, StytchLogin, StytchPasskeyRegistration, StytchPasswordReset, StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser };
|
|
496
|
+
export { IdentityProvider, StytchLogin, StytchPasskeyRegistration, StytchPasswordReset, StytchProvider, useStytch, useStytchIsAuthorized, useStytchSession, useStytchUser, withStytch, withStytchPermissions, withStytchSession, withStytchUser };
|
package/dist/index.js
CHANGED
|
@@ -103,6 +103,87 @@ const withStytchSession$1 = (Component) => {
|
|
|
103
103
|
WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;
|
|
104
104
|
return WithStytchSession;
|
|
105
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Determines whether the logged-in user is allowed to perform the specified action on the specified resource.
|
|
108
|
+
* Returns `true` if the user can perform the action, `false` otherwise.
|
|
109
|
+
*
|
|
110
|
+
* If the user is not logged in, this method will always return false.
|
|
111
|
+
* If the resource or action provided are not valid for the configured RBAC policy, this method will return false.
|
|
112
|
+
*
|
|
113
|
+
* Remember - authorization checks for sensitive actions should always occur on the backend as well.
|
|
114
|
+
* @example
|
|
115
|
+
* const { isAuthorized } = useStytchIsAuthorized<Permissions>('documents', 'edit');
|
|
116
|
+
* return <button disabled={!isAuthorized}>Edit</button>
|
|
117
|
+
*/
|
|
118
|
+
const useStytchIsAuthorized$1 = (resourceId, action) => {
|
|
119
|
+
useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchIsAuthorized', 'StytchProvider'));
|
|
120
|
+
const client = useStytch();
|
|
121
|
+
const { user } = useStytchUser$1();
|
|
122
|
+
const [isAuthorized, setIsAuthorized] = useIsomorphicLayoutEffect.useAsyncState({
|
|
123
|
+
isInitialized: false,
|
|
124
|
+
fromCache: false,
|
|
125
|
+
isAuthorized: false,
|
|
126
|
+
});
|
|
127
|
+
React.useEffect(() => {
|
|
128
|
+
if (StytchSSRProxy.isStytchSSRProxy(client)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
setIsAuthorized({
|
|
132
|
+
isInitialized: true,
|
|
133
|
+
fromCache: true,
|
|
134
|
+
isAuthorized: client.rbac.isAuthorizedSync(resourceId, action),
|
|
135
|
+
});
|
|
136
|
+
}, [action, client, resourceId, setIsAuthorized]);
|
|
137
|
+
React.useEffect(() => {
|
|
138
|
+
if (StytchSSRProxy.isStytchSSRProxy(client)) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
client.rbac.isAuthorized(resourceId, action).then((isAuthorized) => {
|
|
142
|
+
setIsAuthorized({ isAuthorized, fromCache: false, isInitialized: true });
|
|
143
|
+
});
|
|
144
|
+
}, [client, user === null || user === void 0 ? void 0 : user.roles, resourceId, action, setIsAuthorized]);
|
|
145
|
+
return isAuthorized;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Wrap your component with this HOC in order to receive the permissions for the logged-in user.
|
|
149
|
+
* Evaluates all permissions granted to the logged-in user.
|
|
150
|
+
* Returns a Record<RoleId, Record<Action, boolean>> response indicating the user's permissions.
|
|
151
|
+
* Each boolean will be `true` if the user can perform the action, `false` otherwise.
|
|
152
|
+
*
|
|
153
|
+
* If the user is not logged in, all values will be false.
|
|
154
|
+
*
|
|
155
|
+
* Remember - authorization checks for sensitive actions should always occur on the backend as well.
|
|
156
|
+
* @example
|
|
157
|
+
* type Permissions = {
|
|
158
|
+
* document: 'create' | 'read' | 'write
|
|
159
|
+
* image: 'create' | 'read'
|
|
160
|
+
* }
|
|
161
|
+
*
|
|
162
|
+
* const MyComponent = (props) => {
|
|
163
|
+
* const canEditDocuments = props.stytchPermissions.document.edit;
|
|
164
|
+
* const canReadImages = props.stytchPermissions.image.read;
|
|
165
|
+
* }
|
|
166
|
+
* return withStytchPermissions<Permissions>(MyComponent)
|
|
167
|
+
*/
|
|
168
|
+
const withStytchPermissions$1 = (Component) => {
|
|
169
|
+
const WithStytchPermissions = (props) => {
|
|
170
|
+
useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useRBACPermissions', 'StytchProvider'));
|
|
171
|
+
const client = useStytch();
|
|
172
|
+
const { user } = useStytchUser$1();
|
|
173
|
+
const [permissions, setPermissions] = useIsomorphicLayoutEffect.useAsyncState({ loaded: false, value: null });
|
|
174
|
+
React.useEffect(() => {
|
|
175
|
+
client.rbac.allPermissions().then((permissions) => {
|
|
176
|
+
setPermissions({ loaded: true, value: permissions });
|
|
177
|
+
});
|
|
178
|
+
}, [client, user === null || user === void 0 ? void 0 : user.roles, setPermissions]);
|
|
179
|
+
if (!permissions.loaded) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
return React__default["default"].createElement(Component, Object.assign({}, props, { stytchPermissions: permissions.value }));
|
|
183
|
+
};
|
|
184
|
+
WithStytchPermissions.displayName = `withStytchPermissions(${Component.displayName || Component.name || 'Component'})`;
|
|
185
|
+
return WithStytchPermissions;
|
|
186
|
+
};
|
|
106
187
|
/**
|
|
107
188
|
* The Stytch Context Provider.
|
|
108
189
|
* Wrap your application with this component in order to use Stytch everywhere in your app.
|
|
@@ -342,7 +423,7 @@ const StytchPasskeyRegistration = ({ config, styles, callbacks, strings, }) => {
|
|
|
342
423
|
* }}
|
|
343
424
|
* />
|
|
344
425
|
*/
|
|
345
|
-
const IdentityProvider = ({ styles, callbacks, strings }) => {
|
|
426
|
+
const IdentityProvider = ({ styles, callbacks, strings, getIDPConsentManifest }) => {
|
|
346
427
|
useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<IdentityProvider />'));
|
|
347
428
|
const stytchClient = useStytch();
|
|
348
429
|
const user = useStytchUser$1();
|
|
@@ -363,8 +444,9 @@ const IdentityProvider = ({ styles, callbacks, strings }) => {
|
|
|
363
444
|
elementId: `#${containerEl.current.id}`,
|
|
364
445
|
styles,
|
|
365
446
|
strings,
|
|
447
|
+
getIDPConsentManifest,
|
|
366
448
|
});
|
|
367
|
-
}, [stytchClient, styles, callbacks, user, strings]);
|
|
449
|
+
}, [stytchClient, styles, callbacks, user, strings, getIDPConsentManifest]);
|
|
368
450
|
return React__default["default"].createElement("div", { ref: containerEl });
|
|
369
451
|
};
|
|
370
452
|
|
|
@@ -400,6 +482,8 @@ const useStytchUser = useStytchUser$1;
|
|
|
400
482
|
const useStytchSession = useStytchSession$1;
|
|
401
483
|
const withStytchUser = withStytchUser$1;
|
|
402
484
|
const withStytchSession = withStytchSession$1;
|
|
485
|
+
const useStytchIsAuthorized = useStytchIsAuthorized$1;
|
|
486
|
+
const withStytchPermissions = withStytchPermissions$1;
|
|
403
487
|
/**
|
|
404
488
|
* The Stytch Context Provider.
|
|
405
489
|
* Wrap your application with this component in order to use Stytch everywhere in your app.
|
|
@@ -423,8 +507,10 @@ exports.StytchPasskeyRegistration = StytchPasskeyRegistration;
|
|
|
423
507
|
exports.StytchPasswordReset = StytchPasswordReset;
|
|
424
508
|
exports.StytchProvider = StytchProvider;
|
|
425
509
|
exports.useStytch = useStytch;
|
|
510
|
+
exports.useStytchIsAuthorized = useStytchIsAuthorized;
|
|
426
511
|
exports.useStytchSession = useStytchSession;
|
|
427
512
|
exports.useStytchUser = useStytchUser;
|
|
428
513
|
exports.withStytch = withStytch;
|
|
514
|
+
exports.withStytchPermissions = withStytchPermissions;
|
|
429
515
|
exports.withStytchSession = withStytchSession;
|
|
430
516
|
exports.withStytchUser = withStytchUser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stytch/react",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.7.0",
|
|
4
4
|
"description": "Stytch's official React Library",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@stytch/internal-test-utils": "0.0.0",
|
|
40
40
|
"@stytch/internal-tsconfigs": "0.0.0",
|
|
41
41
|
"@stytch/js-utils": "0.0.1",
|
|
42
|
-
"@stytch/vanilla-js": "5.
|
|
42
|
+
"@stytch/vanilla-js": "5.29.0",
|
|
43
43
|
"@testing-library/react": "14.0.0",
|
|
44
44
|
"@types/jest": "29.5.14",
|
|
45
45
|
"eslint-config-custom": "0.0.1",
|