@stytch/react 19.4.3 → 19.5.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +7 -7
  3. package/b2b/headless/package.json +6 -0
  4. package/b2b/ui/package.json +6 -0
  5. package/dist/StytchB2BContext-9c062712.d.ts +272 -0
  6. package/dist/{StytchB2BContext-081081ee.js → StytchB2BContext-9c062712.js} +94 -49
  7. package/dist/StytchB2BContext-c5062f9b.d.ts +272 -0
  8. package/dist/StytchB2BContext-c5062f9b.js +280 -0
  9. package/dist/StytchSSRProxy-34c789b5.d.ts +3 -0
  10. package/dist/StytchSSRProxy-34c789b5.js +48 -0
  11. package/dist/StytchSSRProxy-86bc42b3.d.ts +3 -0
  12. package/dist/StytchSSRProxy-86bc42b3.js +54 -0
  13. package/dist/adminPortal/index.d.ts +1 -1
  14. package/dist/adminPortal/index.esm.d.ts +1 -1
  15. package/dist/adminPortal/index.esm.js +5 -4
  16. package/dist/adminPortal/index.js +5 -4
  17. package/dist/b2b/index.d.ts +180 -19
  18. package/dist/b2b/index.esm.d.ts +180 -19
  19. package/dist/b2b/index.esm.js +91 -18
  20. package/dist/b2b/index.headless.d.ts +16 -0
  21. package/dist/b2b/index.headless.esm.d.ts +16 -0
  22. package/dist/b2b/index.headless.esm.js +24 -0
  23. package/dist/b2b/index.headless.js +28 -0
  24. package/dist/b2b/index.js +99 -26
  25. package/dist/b2b/index.ui.d.ts +17 -0
  26. package/dist/b2b/index.ui.esm.d.ts +17 -0
  27. package/dist/b2b/index.ui.esm.js +25 -0
  28. package/dist/b2b/index.ui.js +29 -0
  29. package/dist/errors-d9d5fbc8.d.ts +5 -0
  30. package/dist/index-b14d4efe.d.ts +1 -1
  31. package/dist/index.d.ts +134 -77
  32. package/dist/index.esm.d.ts +134 -77
  33. package/dist/index.esm.js +153 -94
  34. package/dist/index.headless.d.ts +16 -0
  35. package/dist/index.headless.esm.d.ts +16 -0
  36. package/dist/index.headless.esm.js +24 -0
  37. package/dist/index.headless.js +28 -0
  38. package/dist/index.js +167 -108
  39. package/dist/index.ui.d.ts +17 -0
  40. package/dist/index.ui.esm.d.ts +17 -0
  41. package/dist/index.ui.esm.js +25 -0
  42. package/dist/index.ui.js +29 -0
  43. package/dist/useIsomorphicLayoutEffect-1babb81e.d.ts +24 -0
  44. package/dist/{invariant-568a7633.js → useIsomorphicLayoutEffect-1babb81e.js} +5 -13
  45. package/dist/useIsomorphicLayoutEffect-65746ef3.d.ts +24 -0
  46. package/dist/{invariant-ae5a5bce.js → useIsomorphicLayoutEffect-65746ef3.js} +4 -16
  47. package/package.json +5 -3
  48. package/dist/StytchB2BContext-081081ee.d.ts +0 -165
  49. package/dist/StytchB2BContext-865b6947.d.ts +0 -165
  50. package/dist/StytchB2BContext-865b6947.js +0 -235
  51. package/dist/invariant-568a7633.d.ts +0 -27
  52. package/dist/invariant-ae5a5bce.d.ts +0 -27
package/dist/index.js CHANGED
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
- var invariant = require('./invariant-ae5a5bce.js');
6
+ var useIsomorphicLayoutEffect = require('./useIsomorphicLayoutEffect-65746ef3.js');
7
+ var StytchSSRProxy = require('./StytchSSRProxy-86bc42b3.js');
7
8
 
8
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
10
 
@@ -12,10 +13,12 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
13
  const initialUser = {
13
14
  user: null,
14
15
  fromCache: false,
16
+ isInitialized: false,
15
17
  };
16
18
  const initialSession = {
17
19
  session: null,
18
20
  fromCache: false,
21
+ isInitialized: false,
19
22
  };
20
23
  const StytchContext = React.createContext({ isMounted: false });
21
24
  const StytchUserContext = React.createContext(initialUser);
@@ -26,29 +29,38 @@ const isUIClient = (client) => {
26
29
  };
27
30
  /**
28
31
  * Returns the active User.
32
+ * The Stytch SDKs are used for client-side authentication and session management.
33
+ * Check the isInitialized property to determine if the SDK has completed initialization.
29
34
  * Check the fromCache property to determine if the user data is from persistent storage.
30
35
  * @example
31
- * const {user} = useStytchUser();
36
+ * const {user, isInitialized, fromCache} = useStytchUser();
37
+ * if (!isInitialized) {
38
+ * return <p>Loading...</p>;
39
+ * }
32
40
  * return (<h1>Welcome, {user.name.first_name}</h1>);
33
- * @returns A {@link SWRUser}
34
41
  */
35
- const useStytchUser = () => {
36
- invariant.invariant(useIsMounted__INTERNAL(), invariant.noProviderError('useStytchUser'));
42
+ const useStytchUser$1 = () => {
43
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchUser'));
37
44
  return React.useContext(StytchUserContext);
38
45
  };
39
46
  /**
40
47
  * Returns the active user's Stytch session.
48
+ * The Stytch SDKs are used for client-side authentication and session management.
49
+ * Check the isInitialized property to determine if the SDK has completed initialization.
50
+ * Check the fromCache property to determine if the session data is from persistent storage.
41
51
  * @example
42
- * const {session} = useStytchSession();
52
+ * const {session, isInitialized, fromCache} = useStytchSession();
43
53
  * useEffect(() => {
54
+ * if (!isInitialized) {
55
+ * return;
56
+ * }
44
57
  * if (!session) {
45
58
  * router.replace('/login')
46
59
  * }
47
- * }, [session]);
48
- * @returns A {@link SWRSession}
60
+ * }, [session, isInitialized]);
49
61
  */
50
- const useStytchSession = () => {
51
- invariant.invariant(useIsMounted__INTERNAL(), invariant.noProviderError('useStytchSession'));
62
+ const useStytchSession$1 = () => {
63
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchSession'));
52
64
  return React.useContext(StytchSessionContext);
53
65
  };
54
66
  /**
@@ -62,65 +74,79 @@ const useStytchSession = () => {
62
74
  */
63
75
  const useStytch = () => {
64
76
  const ctx = React.useContext(StytchContext);
65
- invariant.invariant(ctx.isMounted, invariant.noProviderError('useStytch'));
77
+ useIsomorphicLayoutEffect.invariant(ctx.isMounted, StytchSSRProxy.noProviderError('useStytch'));
66
78
  return ctx.client;
67
79
  };
68
80
  const withStytch = (Component) => {
69
81
  const WithStytch = (props) => {
70
- invariant.invariant(useIsMounted__INTERNAL(), invariant.noProviderError('withStytch'));
82
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytch'));
71
83
  return React__default["default"].createElement(Component, Object.assign({}, props, { stytch: useStytch() }));
72
84
  };
73
85
  WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;
74
86
  return WithStytch;
75
87
  };
76
- const withStytchUser = (Component) => {
88
+ const withStytchUser$1 = (Component) => {
77
89
  const WithStytchUser = (props) => {
78
- invariant.invariant(useIsMounted__INTERNAL(), invariant.noProviderError('withStytchUser'));
79
- const { user, fromCache } = useStytchUser();
80
- return React__default["default"].createElement(Component, Object.assign({}, props, { stytchUser: user, stytchUserIsFromCache: fromCache }));
90
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchUser'));
91
+ const { user, isInitialized, fromCache } = useStytchUser$1();
92
+ return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchUser: user, stytchUserIsInitialized: isInitialized, stytchUserIsFromCache: fromCache })));
81
93
  };
82
94
  WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;
83
95
  return WithStytchUser;
84
96
  };
85
- const withStytchSession = (Component) => {
97
+ const withStytchSession$1 = (Component) => {
86
98
  const WithStytchSession = (props) => {
87
- invariant.invariant(useIsMounted__INTERNAL(), invariant.noProviderError('withStytchSession'));
88
- const { session, fromCache } = useStytchSession();
89
- return React__default["default"].createElement(Component, Object.assign({}, props, { stytchSession: session, stytchSessionIsFromCache: fromCache }));
99
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchSession'));
100
+ const { session, isInitialized, fromCache } = useStytchSession$1();
101
+ return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchSession: session, stytchSessionIsInitialized: isInitialized, stytchSessionIsFromCache: fromCache })));
90
102
  };
91
103
  WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;
92
104
  return WithStytchSession;
93
105
  };
94
106
  /**
95
107
  * The Stytch Context Provider.
96
- * Wrap your application with this component in the root file in order to use Stytch everywhere in your app.
108
+ * Wrap your application with this component in order to use Stytch everywhere in your app.
97
109
  * @example
98
- * const stytch = new StytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
110
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
99
111
  *
100
- * ReactDOM.render(
112
+ * return (
101
113
  * <StytchProvider stytch={stytch}>
102
114
  * <App />
103
- * </StytchProvider>,
104
- * document.getElementById('root'),
115
+ * </StytchProvider>
105
116
  * )
106
117
  */
107
- const StytchProvider = ({ stytch, children, }) => {
108
- invariant.invariant(!useIsMounted__INTERNAL(), invariant.providerMustBeUniqueError);
109
- invariant.invariant(typeof window !== 'undefined', invariant.noSSRError);
118
+ const StytchProvider$1 = ({ stytch, children, assumeHydrated = false, }) => {
119
+ useIsomorphicLayoutEffect.invariant(!useIsMounted__INTERNAL(), StytchSSRProxy.providerMustBeUniqueError);
120
+ useIsomorphicLayoutEffect.invariant(!assumeHydrated || typeof window !== 'undefined', 'The `assumeHydrated` prop must be set to `false` when using StytchProvider in a server environment.');
110
121
  const ctx = React.useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);
111
- const [{ user, session }, setClientState] = invariant.useAsyncState({
112
- session: stytch.session.getInfo(),
113
- user: stytch.user.getInfo(),
114
- });
115
- React.useEffect(() => stytch.onStateChange(() => {
116
- setClientState((oldState) => {
117
- const newState = {
118
- session: stytch.session.getInfo(),
119
- user: stytch.user.getInfo(),
120
- };
121
- return invariant.mergeWithStableProps(oldState, newState);
122
- });
123
- }), [setClientState, stytch]);
122
+ const getHydratedState = React.useCallback(() => {
123
+ return {
124
+ session: Object.assign(Object.assign({}, stytch.session.getInfo()), { isInitialized: true }),
125
+ user: Object.assign(Object.assign({}, stytch.user.getInfo()), { isInitialized: true }),
126
+ };
127
+ }, [stytch]);
128
+ const getInitialState = () => {
129
+ return {
130
+ session: initialSession,
131
+ user: initialUser,
132
+ };
133
+ };
134
+ const [{ user, session }, setClientState] = useIsomorphicLayoutEffect.useAsyncState(() => assumeHydrated ? getHydratedState() : getInitialState());
135
+ // Store the initial value of `assumeHydrated` in a ref, because it is
136
+ // logically only relevant for the first render
137
+ const assumeHydratedRef = React.useRef(assumeHydrated);
138
+ React.useEffect(() => {
139
+ if (StytchSSRProxy.isStytchSSRProxy(stytch)) {
140
+ return;
141
+ }
142
+ const updateState = () => {
143
+ setClientState((oldState) => useIsomorphicLayoutEffect.mergeWithStableProps(oldState, getHydratedState()));
144
+ };
145
+ if (!assumeHydratedRef.current) {
146
+ updateState();
147
+ }
148
+ return stytch.onStateChange(updateState);
149
+ }, [getHydratedState, setClientState, stytch]);
124
150
  return (React__default["default"].createElement(StytchContext.Provider, { value: ctx },
125
151
  React__default["default"].createElement(StytchUserContext.Provider, { value: user },
126
152
  React__default["default"].createElement(StytchSessionContext.Provider, { value: session }, children))));
@@ -128,10 +154,10 @@ const StytchProvider = ({ stytch, children, }) => {
128
154
 
129
155
  /**
130
156
  * The Stytch Login Screen component.
131
- * This component can only be used with a {@link StytchUIClient} client constructor
132
- * passed into the {@link StytchProvider}
157
+ * This component can only be used with a Stytch UI Client
158
+ * passed into the StytchProvider.
133
159
  *
134
- * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
160
+ * See the {@link https://stytch.com/docs/sdks online reference}
135
161
  *
136
162
  * @example
137
163
  * <StytchLogin
@@ -154,15 +180,14 @@ const StytchProvider = ({ stytch, children, }) => {
154
180
  * onEvent: (event) => console.log(event)
155
181
  * }}
156
182
  * />
157
- * @param props {@link StytchProps}
158
183
  */
159
184
  const StytchLogin = ({ config, styles, callbacks, }) => {
160
- invariant.invariant(useIsMounted__INTERNAL(), invariant.noProviderError('<StytchLogin />'));
185
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchLogin />'));
161
186
  const stytchClient = useStytch();
162
187
  const containerEl = React.useRef(null);
163
- React.useLayoutEffect(() => {
188
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
164
189
  if (!isUIClient(stytchClient)) {
165
- throw Error(invariant.noHeadlessClientError);
190
+ throw Error(StytchSSRProxy.noHeadlessClientError);
166
191
  }
167
192
  if (!containerEl.current) {
168
193
  return;
@@ -172,7 +197,7 @@ const StytchLogin = ({ config, styles, callbacks, }) => {
172
197
  containerEl.current.id = `stytch-magic-link-${randId}`;
173
198
  }
174
199
  stytchClient.mountLogin({
175
- config: config,
200
+ config,
176
201
  callbacks,
177
202
  elementId: `#${containerEl.current.id}`,
178
203
  styles,
@@ -182,10 +207,10 @@ const StytchLogin = ({ config, styles, callbacks, }) => {
182
207
  };
183
208
  /**
184
209
  * The Stytch Reset Password component.
185
- * This component can only be used with a {@link StytchUIClient} client constructor
186
- * passed into the {@link StytchProvider}
210
+ * This component can only be used with a Stytch UI Client
211
+ * passed into the StytchProvider.
187
212
  *
188
- * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
213
+ * See the {@link https://stytch.com/docs/sdks online reference}
189
214
  *
190
215
  * @example
191
216
  * <StytchPasswordReset
@@ -209,19 +234,14 @@ const StytchLogin = ({ config, styles, callbacks, }) => {
209
234
  * onEvent: (event) => console.log(event)
210
235
  * }}
211
236
  * />
212
- *
213
- * @param config - A {@link StytchLoginConfig} object
214
- * @param passwordResetToken - A Stytch password reset token
215
- * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
216
- * @param callbacks - An optional {@link Callbacks} object
217
237
  */
218
238
  const StytchPasswordReset = ({ config, styles, callbacks, passwordResetToken, }) => {
219
- invariant.invariant(useIsMounted__INTERNAL(), invariant.noProviderError('<StytchResetPassword />'));
239
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchResetPassword />'));
220
240
  const stytchClient = useStytch();
221
241
  const containerEl = React.useRef(null);
222
- React.useLayoutEffect(() => {
242
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
223
243
  if (!isUIClient(stytchClient)) {
224
- throw Error(invariant.noHeadlessClientError);
244
+ throw Error(StytchSSRProxy.noHeadlessClientError);
225
245
  }
226
246
  if (!containerEl.current) {
227
247
  return;
@@ -232,7 +252,7 @@ const StytchPasswordReset = ({ config, styles, callbacks, passwordResetToken, })
232
252
  }
233
253
  if (passwordResetToken) {
234
254
  stytchClient.mountResetPassword({
235
- config: config,
255
+ config,
236
256
  callbacks,
237
257
  elementId: `#${containerEl.current.id}`,
238
258
  styles,
@@ -242,53 +262,46 @@ const StytchPasswordReset = ({ config, styles, callbacks, passwordResetToken, })
242
262
  }, [stytchClient, config, styles, callbacks, passwordResetToken]);
243
263
  return React__default["default"].createElement("div", { ref: containerEl });
244
264
  };
265
+ /**
266
+ * The Stytch Passkey Registration component.
267
+ * This component can only be used with a Stytch UI Client
268
+ * passed into the StytchProvider.
269
+ *
270
+ * See the {@link https://stytch.com/docs/sdks online reference}
271
+ *
272
+ * @example
273
+ * const styles = {
274
+ * container: {
275
+ * backgroundColor: '#e11e1e',
276
+ * },
277
+ * colors: {
278
+ * primary: '#ff00f7',
279
+ * secondary: '#5C727D',
280
+ * },
281
+ * }
282
+ *
283
+ * <StytchPasskeyRegistration
284
+ * styles={styles}
285
+ * callbacks={{
286
+ * onEvent: (event) => console.log(event)
287
+ * }}
288
+ * />
289
+ */
245
290
  const StytchPasskeyRegistration = ({ config, styles, callbacks, }) => {
246
- /**
247
- * The Stytch Passkey Registration component.
248
- * This component can only be used with a {@link StytchUIClient} client constructor
249
- * passed into the {@link StytchProvider}
250
- *
251
- * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
252
- *
253
- *
254
- * @example
255
- * const styles = {
256
- * container: {
257
- * backgroundColor: '#e11e1e',
258
- * },
259
- * colors: {
260
- * primary: '#ff00f7',
261
- * secondary: '#5C727D',
262
- * },
263
- * }
264
- *
265
- * <StytchPasskeyRegistration
266
- * config={{
267
- * products: ['passkey'],
268
- * }}
269
- * styles={styles}
270
- * callbacks={{
271
- * onEvent: (event) => console.log(event)
272
- * }}
273
- * />
274
- * @param config - A {@link StytchLoginConfig} object
275
- * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
276
- * @param callbacks - An optional {@link Callbacks} object
277
- */
278
- invariant.invariant(useIsMounted__INTERNAL(), invariant.noProviderError('<StytchPasskeyRegistration />'));
291
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchPasskeyRegistration />'));
279
292
  const stytchClient = useStytch();
280
- const user = useStytchUser();
293
+ const user = useStytchUser$1();
281
294
  const containerEl = React.useRef(null);
282
- React.useLayoutEffect(() => {
295
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
283
296
  if (!isUIClient(stytchClient)) {
284
- throw Error(invariant.noHeadlessClientError);
297
+ throw Error(StytchSSRProxy.noHeadlessClientError);
285
298
  }
286
299
  if (!containerEl.current) {
287
300
  return;
288
301
  }
289
302
  if (!containerEl.current.id) {
290
303
  const randId = Math.floor(Math.random() * 1e6);
291
- containerEl.current.id = `stytch-reset-passkey-${randId}`;
304
+ containerEl.current.id = `stytch-passkey-registration-${randId}`;
292
305
  }
293
306
  stytchClient.mountPasskeyRegistration({
294
307
  config,
@@ -303,11 +316,10 @@ const StytchPasskeyRegistration = ({ config, styles, callbacks, }) => {
303
316
  * The Stytch IDP component.
304
317
  * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
305
318
  * Requires the user to be logged in.
306
- * This component can only be used with a {@link StytchUIClient} client constructor
307
- * passed into the {@link StytchProvider}
308
- *
309
- * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
319
+ * This component can only be used with a Stytch UI Client
320
+ * passed into the StytchProvider.
310
321
  *
322
+ * See the {@link https://stytch.com/docs/sdks online reference}
311
323
  *
312
324
  * @example
313
325
  * const styles = {
@@ -326,17 +338,15 @@ const StytchPasskeyRegistration = ({ config, styles, callbacks, }) => {
326
338
  * onEvent: (event) => console.log(event)
327
339
  * }}
328
340
  * />
329
- * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
330
- * @param callbacks - An optional {@link Callbacks} object
331
341
  */
332
342
  const IdentityProvider = ({ styles, callbacks }) => {
333
- invariant.invariant(useIsMounted__INTERNAL(), invariant.noProviderError('<IdentityProvider />'));
343
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<IdentityProvider />'));
334
344
  const stytchClient = useStytch();
335
- const user = useStytchUser();
345
+ const user = useStytchUser$1();
336
346
  const containerEl = React.useRef(null);
337
- React.useLayoutEffect(() => {
347
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
338
348
  if (!isUIClient(stytchClient)) {
339
- throw Error(invariant.noHeadlessClientError);
349
+ throw Error(StytchSSRProxy.noHeadlessClientError);
340
350
  }
341
351
  if (!containerEl.current) {
342
352
  return;
@@ -354,6 +364,55 @@ const IdentityProvider = ({ styles, callbacks }) => {
354
364
  return React__default["default"].createElement("div", { ref: containerEl });
355
365
  };
356
366
 
367
+ /**
368
+ * Returns the active User.
369
+ * The Stytch SDKs are used for client-side authentication and session management.
370
+ * Check the isInitialized property to determine if the SDK has completed initialization.
371
+ * Check the fromCache property to determine if the user data is from persistent storage.
372
+ * @example
373
+ * const {user, isInitialized, fromCache} = useStytchUser();
374
+ * if (!isInitialized) {
375
+ * return <p>Loading...</p>;
376
+ * }
377
+ * return (<h1>Welcome, {user.name.first_name}</h1>);
378
+ */
379
+ const useStytchUser = useStytchUser$1;
380
+ /**
381
+ * Returns the active user's Stytch session.
382
+ * The Stytch SDKs are used for client-side authentication and session management.
383
+ * Check the isInitialized property to determine if the SDK has completed initialization.
384
+ * Check the fromCache property to determine if the session data is from persistent storage.
385
+ * @example
386
+ * const {session, isInitialized, fromCache} = useStytchSession();
387
+ * useEffect(() => {
388
+ * if (!isInitialized) {
389
+ * return;
390
+ * }
391
+ * if (!session) {
392
+ * router.replace('/login')
393
+ * }
394
+ * }, [session, isInitialized]);
395
+ */
396
+ const useStytchSession = useStytchSession$1;
397
+ const withStytchUser = withStytchUser$1;
398
+ const withStytchSession = withStytchSession$1;
399
+ /**
400
+ * The Stytch Context Provider.
401
+ * Wrap your application with this component in order to use Stytch everywhere in your app.
402
+ * @example
403
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
404
+ *
405
+ * ReactDOM.render(
406
+ * <StytchProvider stytch={stytch}>
407
+ * <App />
408
+ * </StytchProvider>,
409
+ * document.getElementById('root'),
410
+ * )
411
+ */
412
+ const StytchProvider = ({ stytch, children, assumeHydrated = true, }) => {
413
+ return (React__default["default"].createElement(StytchProvider$1, { stytch: stytch, assumeHydrated: assumeHydrated }, children));
414
+ };
415
+
357
416
  exports.IdentityProvider = IdentityProvider;
358
417
  exports.StytchLogin = StytchLogin;
359
418
  exports.StytchPasskeyRegistration = StytchPasskeyRegistration;
@@ -0,0 +1,17 @@
1
+ import { StytchUIClient } from "@stytch/vanilla-js";
2
+ /**
3
+ * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.
4
+ * The Stytch client is not available serverside.
5
+ * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.
6
+ * @example
7
+ * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')
8
+ *
9
+ * return (
10
+ * <StytchProvider stytch={stytch}>
11
+ * <App />
12
+ * </StytchProvider>
13
+ * )
14
+ * @returns A {@link StytchUIClient}
15
+ */
16
+ declare const createStytchUIClient: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>(_PUBLIC_TOKEN: string, options?: import("@stytch/core/public").StytchClientOptions | undefined) => StytchUIClient<TProjectConfiguration>;
17
+ export { createStytchUIClient };
@@ -0,0 +1,17 @@
1
+ import { StytchUIClient } from "@stytch/vanilla-js";
2
+ /**
3
+ * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.
4
+ * The Stytch client is not available serverside.
5
+ * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.
6
+ * @example
7
+ * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')
8
+ *
9
+ * return (
10
+ * <StytchProvider stytch={stytch}>
11
+ * <App />
12
+ * </StytchProvider>
13
+ * )
14
+ * @returns A {@link StytchUIClient}
15
+ */
16
+ declare const createStytchUIClient: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>(_PUBLIC_TOKEN: string, options?: import("@stytch/core/public").StytchClientOptions | undefined) => StytchUIClient<TProjectConfiguration>;
17
+ export { createStytchUIClient };
@@ -0,0 +1,25 @@
1
+ import { StytchUIClient } from '@stytch/vanilla-js';
2
+ import { c as createStytchSSRProxy } from './StytchSSRProxy-34c789b5.js';
3
+
4
+ /**
5
+ * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.
6
+ * The Stytch client is not available serverside.
7
+ * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.
8
+ * @example
9
+ * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')
10
+ *
11
+ * return (
12
+ * <StytchProvider stytch={stytch}>
13
+ * <App />
14
+ * </StytchProvider>
15
+ * )
16
+ * @returns A {@link StytchUIClient}
17
+ */
18
+ const createStytchUIClient = (...args) => {
19
+ if (typeof window === 'undefined') {
20
+ return createStytchSSRProxy();
21
+ }
22
+ return new StytchUIClient(...args);
23
+ };
24
+
25
+ export { createStytchUIClient };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var vanillaJs = require('@stytch/vanilla-js');
6
+ var StytchSSRProxy = require('./StytchSSRProxy-86bc42b3.js');
7
+
8
+ /**
9
+ * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.
10
+ * The Stytch client is not available serverside.
11
+ * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.
12
+ * @example
13
+ * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')
14
+ *
15
+ * return (
16
+ * <StytchProvider stytch={stytch}>
17
+ * <App />
18
+ * </StytchProvider>
19
+ * )
20
+ * @returns A {@link StytchUIClient}
21
+ */
22
+ const createStytchUIClient = (...args) => {
23
+ if (typeof window === 'undefined') {
24
+ return StytchSSRProxy.createStytchSSRProxy();
25
+ }
26
+ return new vanillaJs.StytchUIClient(...args);
27
+ };
28
+
29
+ exports.createStytchUIClient = createStytchUIClient;
@@ -0,0 +1,24 @@
1
+ import { Dispatch, SetStateAction, useEffect } from "react";
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ declare function invariant(cond: any, message: string): asserts cond;
4
+ // useState can cause memory leaks if it is set after the component unmounted. For example, if it is
5
+ // set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.
6
+ declare const useAsyncState: <T>(initialState: T | (() => T)) => [
7
+ T,
8
+ Dispatch<SetStateAction<T>>
9
+ ];
10
+ /**
11
+ * Returns a version of `newValue` whose properties that are deeply equal to
12
+ * those in `oldValue` are replaced with those from `oldValue`. This provides a
13
+ * limited form of "structural sharing" that provides a stable reference for
14
+ * unchanged slices of the object.
15
+ *
16
+ * If `oldValue` and `newValue` are referentially equal, the same value is
17
+ * returned.
18
+ *
19
+ * @param oldValue The old value
20
+ * @param newValue The new value
21
+ */
22
+ declare const mergeWithStableProps: <T extends Record<string, unknown>, U extends Record<string, unknown> = T>(oldValue: U, newValue: T) => T;
23
+ declare const useIsomorphicLayoutEffect: typeof useEffect;
24
+ export { useIsomorphicLayoutEffect as default, invariant, useAsyncState, mergeWithStableProps };
@@ -1,4 +1,4 @@
1
- import { useRef, useState, useEffect, useCallback } from 'react';
1
+ import { useRef, useState, useEffect, useCallback, useLayoutEffect } from 'react';
2
2
 
3
3
  const createDeepEqual = ({ KEYS_TO_EXCLUDE = [] } = {}) => {
4
4
  // If comparing functions, this may need some work. Not sure the
@@ -68,21 +68,13 @@ const useAsyncState = (initialState) => {
68
68
  return [state, setStateAction];
69
69
  };
70
70
 
71
- const noProviderError = (item, provider = 'StytchProvider') => `${item} can only be used inside <${provider}>.`;
72
- const providerMustBeUniqueError = 'You cannot render a <StytchProvider> inside another <StytchProvider>.';
73
- const B2BProviderMustBeUniqueError = 'You cannot render a <StytchB2BProvider> inside another <StytchB2BProvider>.';
74
- const noSSRError = `The @stytch/react library is not meant for use with serverside environments like NextJS.
75
- Use the @stytch/nextjs library instead -
76
- npm remove @stytch/react && npm install @stytch/nextjs
77
- `;
78
- const noHeadlessClientError = `Tried to create a Stytch Login UI element using the Stytch Headless SDK.
79
- You must use the UI SDK to use UI elements.
80
- Please make sure you are importing from @stytch/vanilla-js and not from the @stytch/vanilla-js/headless.`;
81
-
82
71
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
72
  function invariant(cond, message) {
84
73
  if (!cond)
85
74
  throw new Error(message);
86
75
  }
87
76
 
88
- export { B2BProviderMustBeUniqueError as B, noSSRError as a, noHeadlessClientError as b, invariant as i, mergeWithStableProps as m, noProviderError as n, providerMustBeUniqueError as p, useAsyncState as u };
77
+ // cc https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
78
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
79
+
80
+ export { useIsomorphicLayoutEffect as a, invariant as i, mergeWithStableProps as m, useAsyncState as u };
@@ -0,0 +1,24 @@
1
+ import { Dispatch, SetStateAction, useEffect } from "react";
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ declare function invariant(cond: any, message: string): asserts cond;
4
+ // useState can cause memory leaks if it is set after the component unmounted. For example, if it is
5
+ // set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.
6
+ declare const useAsyncState: <T>(initialState: T | (() => T)) => [
7
+ T,
8
+ Dispatch<SetStateAction<T>>
9
+ ];
10
+ /**
11
+ * Returns a version of `newValue` whose properties that are deeply equal to
12
+ * those in `oldValue` are replaced with those from `oldValue`. This provides a
13
+ * limited form of "structural sharing" that provides a stable reference for
14
+ * unchanged slices of the object.
15
+ *
16
+ * If `oldValue` and `newValue` are referentially equal, the same value is
17
+ * returned.
18
+ *
19
+ * @param oldValue The old value
20
+ * @param newValue The new value
21
+ */
22
+ declare const mergeWithStableProps: <T extends Record<string, unknown>, U extends Record<string, unknown> = T>(oldValue: U, newValue: T) => T;
23
+ declare const useIsomorphicLayoutEffect: typeof useEffect;
24
+ export { useIsomorphicLayoutEffect as default, invariant, useAsyncState, mergeWithStableProps };
@@ -70,28 +70,16 @@ const useAsyncState = (initialState) => {
70
70
  return [state, setStateAction];
71
71
  };
72
72
 
73
- const noProviderError = (item, provider = 'StytchProvider') => `${item} can only be used inside <${provider}>.`;
74
- const providerMustBeUniqueError = 'You cannot render a <StytchProvider> inside another <StytchProvider>.';
75
- const B2BProviderMustBeUniqueError = 'You cannot render a <StytchB2BProvider> inside another <StytchB2BProvider>.';
76
- const noSSRError = `The @stytch/react library is not meant for use with serverside environments like NextJS.
77
- Use the @stytch/nextjs library instead -
78
- npm remove @stytch/react && npm install @stytch/nextjs
79
- `;
80
- const noHeadlessClientError = `Tried to create a Stytch Login UI element using the Stytch Headless SDK.
81
- You must use the UI SDK to use UI elements.
82
- Please make sure you are importing from @stytch/vanilla-js and not from the @stytch/vanilla-js/headless.`;
83
-
84
73
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
74
  function invariant(cond, message) {
86
75
  if (!cond)
87
76
  throw new Error(message);
88
77
  }
89
78
 
90
- exports.B2BProviderMustBeUniqueError = B2BProviderMustBeUniqueError;
79
+ // cc https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
80
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
81
+
91
82
  exports.invariant = invariant;
92
83
  exports.mergeWithStableProps = mergeWithStableProps;
93
- exports.noHeadlessClientError = noHeadlessClientError;
94
- exports.noProviderError = noProviderError;
95
- exports.noSSRError = noSSRError;
96
- exports.providerMustBeUniqueError = providerMustBeUniqueError;
97
84
  exports.useAsyncState = useAsyncState;
85
+ exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;