@stytch/nextjs 21.3.0 → 21.4.1

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @stytch/nextjs
2
2
 
3
+ ## 21.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 9997775: Avoid warnings about useLayoutEffect with server rendering
8
+
9
+ ## 21.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 0abb940: feat: Connected Apps OAuth Authorization component support (BETA)
14
+
3
15
  ## 21.3.0
4
16
 
5
17
  ### Minor Changes
@@ -1,6 +1,6 @@
1
1
  import React, { createContext, useContext, useEffect, useMemo } from 'react';
2
2
  import { i as isStytchSSRProxy, n as noProviderError } from './StytchSSRProxy-14916009.js';
3
- import { i as invariant, u as useAsyncState, m as mergeWithStableProps } from './async-b1e10055.js';
3
+ import { i as invariant, u as useAsyncState, m as mergeWithStableProps } from './useIsomorphicLayoutEffect-8da8c061.js';
4
4
 
5
5
  const initialMember = {
6
6
  member: null,
@@ -255,4 +255,4 @@ const StytchB2BProvider = ({ stytch, children, }) => {
255
255
  React.createElement(StytchMemberSessionContext.Provider, { value: session }, children)))));
256
256
  };
257
257
 
258
- export { StytchB2BProvider as S, useStytchB2BClient as a, useStytchMemberSession as b, useStytchMember as c, useStytchIsAuthorized as d, useStytchOrganization as e, withStytchMemberSession as f, withStytchMember as g, withStytchOrganization as h, isUIClient as i, withStytchPermissions as j, useIsMounted__INTERNAL as u, withStytchB2BClient as w };
258
+ export { StytchB2BProvider as S, useStytchB2BClient as a, useStytchMember as b, useStytchMemberSession as c, useStytchIsAuthorized as d, useStytchOrganization as e, withStytchMemberSession as f, withStytchMember as g, withStytchOrganization as h, isUIClient as i, withStytchPermissions as j, useIsMounted__INTERNAL as u, withStytchB2BClient as w };
@@ -2,7 +2,7 @@
2
2
 
3
3
  var React = require('react');
4
4
  var StytchSSRProxy = require('./StytchSSRProxy-63bc6323.js');
5
- var async = require('./async-86a7f0d6.js');
5
+ var useIsomorphicLayoutEffect = require('./useIsomorphicLayoutEffect-41b6e419.js');
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -45,7 +45,7 @@ const isUIClient = (client) => {
45
45
  * return (<h1>Welcome, {member.name}</h1>);
46
46
  */
47
47
  const useStytchMember = () => {
48
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchMember', 'StytchB2BProvider'));
48
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchMember', 'StytchB2BProvider'));
49
49
  return React.useContext(StytchMemberContext);
50
50
  };
51
51
  /**
@@ -66,7 +66,7 @@ const useStytchMember = () => {
66
66
  * }, [session, isInitialized]);
67
67
  */
68
68
  const useStytchMemberSession = () => {
69
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchMemberSession', 'StytchB2BProvider'));
69
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchMemberSession', 'StytchB2BProvider'));
70
70
  return React.useContext(StytchMemberSessionContext);
71
71
  };
72
72
  /**
@@ -83,7 +83,7 @@ const useStytchMemberSession = () => {
83
83
  * return (<p>Welcome to {organization.organization_name}</p>);
84
84
  */
85
85
  const useStytchOrganization = () => {
86
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchOrganization', 'StytchB2BProvider'));
86
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchOrganization', 'StytchB2BProvider'));
87
87
  return React.useContext(StytchOrganizationContext);
88
88
  };
89
89
  /**
@@ -99,10 +99,10 @@ const useStytchOrganization = () => {
99
99
  * return <button disabled={!isAuthorized}>Edit</button>
100
100
  */
101
101
  const useStytchIsAuthorized = (resourceId, action) => {
102
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchIsAuthorized', 'StytchB2BProvider'));
102
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchIsAuthorized', 'StytchB2BProvider'));
103
103
  const client = useStytchB2BClient();
104
104
  const { session } = useStytchMemberSession();
105
- const [isAuthorized, setIsAuthorized] = async.useAsyncState({
105
+ const [isAuthorized, setIsAuthorized] = useIsomorphicLayoutEffect.useAsyncState({
106
106
  isInitialized: false,
107
107
  fromCache: false,
108
108
  isAuthorized: false,
@@ -138,12 +138,12 @@ const useStytchIsAuthorized = (resourceId, action) => {
138
138
  */
139
139
  const useStytchB2BClient = () => {
140
140
  const ctx = React.useContext(StytchContext);
141
- async.invariant(ctx.isMounted, StytchSSRProxy.noProviderError('useStytchB2BClient', 'StytchB2BProvider'));
141
+ useIsomorphicLayoutEffect.invariant(ctx.isMounted, StytchSSRProxy.noProviderError('useStytchB2BClient', 'StytchB2BProvider'));
142
142
  return ctx.client;
143
143
  };
144
144
  const withStytchB2BClient = (Component) => {
145
145
  const WithStytch = (props) => {
146
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchB2BClient', 'StytchB2BProvider'));
146
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchB2BClient', 'StytchB2BProvider'));
147
147
  return React__default["default"].createElement(Component, Object.assign({}, props, { stytch: useStytchB2BClient() }));
148
148
  };
149
149
  WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;
@@ -151,7 +151,7 @@ const withStytchB2BClient = (Component) => {
151
151
  };
152
152
  const withStytchMember = (Component) => {
153
153
  const WithStytchUser = (props) => {
154
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchMember', 'StytchB2BProvider'));
154
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchMember', 'StytchB2BProvider'));
155
155
  const { member, isInitialized, fromCache } = useStytchMember();
156
156
  return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchMember: member, stytchMemberIsInitialized: isInitialized, stytchMemberIsFromCache: fromCache })));
157
157
  };
@@ -160,7 +160,7 @@ const withStytchMember = (Component) => {
160
160
  };
161
161
  const withStytchMemberSession = (Component) => {
162
162
  const WithStytchSession = (props) => {
163
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchMemberSession', 'StytchB2BProvider'));
163
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchMemberSession', 'StytchB2BProvider'));
164
164
  const { session, isInitialized, fromCache } = useStytchMemberSession();
165
165
  return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchMemberSession: session, stytchMemberSessionIsInitialized: isInitialized, stytchMemberSessionIsFromCache: fromCache })));
166
166
  };
@@ -169,7 +169,7 @@ const withStytchMemberSession = (Component) => {
169
169
  };
170
170
  const withStytchOrganization = (Component) => {
171
171
  const WithStytchOrganization = (props) => {
172
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchOrganization', 'StytchB2BProvider'));
172
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchOrganization', 'StytchB2BProvider'));
173
173
  const { organization, isInitialized, fromCache } = useStytchOrganization();
174
174
  return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchOrganization: organization, stytchOrganizationIsInitialized: isInitialized, stytchOrganizationIsFromCache: fromCache })));
175
175
  };
@@ -199,10 +199,10 @@ const withStytchOrganization = (Component) => {
199
199
  */
200
200
  const withStytchPermissions = (Component) => {
201
201
  const WithStytchPermissions = (props) => {
202
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useRBACPermissions', 'StytchB2BProvider'));
202
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useRBACPermissions', 'StytchB2BProvider'));
203
203
  const client = useStytchB2BClient();
204
204
  const { session } = useStytchMemberSession();
205
- const [permissions, setPermissions] = async.useAsyncState({ loaded: false, value: null });
205
+ const [permissions, setPermissions] = useIsomorphicLayoutEffect.useAsyncState({ loaded: false, value: null });
206
206
  React.useEffect(() => {
207
207
  client.rbac
208
208
  .allPermissions()
@@ -230,7 +230,7 @@ const withStytchPermissions = (Component) => {
230
230
  */
231
231
  const StytchB2BProvider = ({ stytch, children, }) => {
232
232
  const ctx = React.useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);
233
- const [{ member, session, organization }, setClientState] = async.useAsyncState({
233
+ const [{ member, session, organization }, setClientState] = useIsomorphicLayoutEffect.useAsyncState({
234
234
  member: initialMember,
235
235
  session: initialMemberSession,
236
236
  organization: initialOrganization,
@@ -251,7 +251,7 @@ const StytchB2BProvider = ({ stytch, children, }) => {
251
251
  session: Object.assign(Object.assign({}, stytch.session.getInfo()), { isInitialized: true }),
252
252
  organization: Object.assign(Object.assign({}, stytch.organization.getInfo()), { isInitialized: true }),
253
253
  };
254
- return async.mergeWithStableProps(oldState, newState);
254
+ return useIsomorphicLayoutEffect.mergeWithStableProps(oldState, newState);
255
255
  });
256
256
  });
257
257
  }, [setClientState, stytch]);
@@ -1,16 +1,16 @@
1
1
  import { mountAdminPortalSSO, mountAdminPortalOrgSettings, mountAdminPortalMemberManagement, mountAdminPortalSCIM } from '@stytch/vanilla-js/b2b/adminPortal';
2
2
  export { AdminPortalB2BProducts } from '@stytch/vanilla-js/b2b/adminPortal';
3
- import React, { useRef, useLayoutEffect } from 'react';
4
- import { u as useIsMounted__INTERNAL, a as useStytchB2BClient } from '../StytchB2BContext-72d99610.js';
3
+ import React, { useRef } from 'react';
4
+ import { u as useIsMounted__INTERNAL, a as useStytchB2BClient } from '../StytchB2BContext-03d66270.js';
5
5
  import { n as noProviderError } from '../StytchSSRProxy-14916009.js';
6
- import { i as invariant } from '../async-b1e10055.js';
6
+ import { i as invariant, a as useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect-8da8c061.js';
7
7
 
8
8
  const makeAdminPortalComponent = (mountFn, componentName) => {
9
9
  const Component = (props) => {
10
10
  invariant(useIsMounted__INTERNAL(), noProviderError(`<${componentName} />`, 'StytchB2BProvider'));
11
11
  const stytchClient = useStytchB2BClient();
12
12
  const containerEl = useRef(null);
13
- useLayoutEffect(() => {
13
+ useIsomorphicLayoutEffect(() => {
14
14
  if (!containerEl.current) {
15
15
  return;
16
16
  }
@@ -4,9 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var adminPortal = require('@stytch/vanilla-js/b2b/adminPortal');
6
6
  var React = require('react');
7
- var StytchB2BContext = require('../StytchB2BContext-8246a922.js');
7
+ var StytchB2BContext = require('../StytchB2BContext-156a7bdd.js');
8
8
  var StytchSSRProxy = require('../StytchSSRProxy-63bc6323.js');
9
- var async = require('../async-86a7f0d6.js');
9
+ var useIsomorphicLayoutEffect = require('../useIsomorphicLayoutEffect-41b6e419.js');
10
10
 
11
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
12
 
@@ -14,10 +14,10 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
14
14
 
15
15
  const makeAdminPortalComponent = (mountFn, componentName) => {
16
16
  const Component = (props) => {
17
- async.invariant(StytchB2BContext.useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError(`<${componentName} />`, 'StytchB2BProvider'));
17
+ useIsomorphicLayoutEffect.invariant(StytchB2BContext.useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError(`<${componentName} />`, 'StytchB2BProvider'));
18
18
  const stytchClient = StytchB2BContext.useStytchB2BClient();
19
19
  const containerEl = React.useRef(null);
20
- React.useLayoutEffect(() => {
20
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
21
21
  if (!containerEl.current) {
22
22
  return;
23
23
  }
@@ -1,6 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import React from "react";
3
3
  import { Callbacks, StyleConfig, StytchB2BUIConfig, StytchProjectConfigurationInput } from "@stytch/vanilla-js";
4
+ // We need to import the StytchB2BUIClient type to give the TSDoc parser a hint as to where it is from
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+ import { IDPConsentScreenManifest } from "@stytch/vanilla-js/b2b";
4
7
  interface StytchB2BProps<TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration> {
5
8
  /**
6
9
  * An optional {@link StyleConfig} to customize the look and feel of the screen.
@@ -68,6 +71,13 @@ interface StytchB2BProps<TProjectConfiguration extends StytchProjectConfiguratio
68
71
  */
69
72
  config: StytchB2BUIConfig;
70
73
  }
74
+ type B2BIDPConsentManifestGenerator = (input: {
75
+ scopes: string[];
76
+ clientName: string;
77
+ }) => IDPConsentScreenManifest;
78
+ type B2BIdentityProviderProps = Omit<StytchB2BProps, "config"> & {
79
+ getIDPConsentManifest?: B2BIDPConsentManifestGenerator;
80
+ };
71
81
  /**
72
82
  * The Stytch B2B UI component.
73
83
  * This component can only be used with a {@link StytchB2BUIClient} client constructor
@@ -103,6 +113,38 @@ interface StytchB2BProps<TProjectConfiguration extends StytchProjectConfiguratio
103
113
  * @param props {@link StytchB2BProps}
104
114
  */
105
115
  declare const StytchB2B: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>({ styles, callbacks, config }: StytchB2BProps<TProjectConfiguration>) => React.JSX.Element;
106
- export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, useStytchIsAuthorized, useStytchOrganization, withStytchB2BClient, withStytchMemberSession, withStytchMember, withStytchOrganization, withStytchPermissions } from "../StytchB2BContext-8246a922.js";
107
- export { StytchB2B };
108
- export type { StytchB2BProviderProps } from "../StytchB2BContext-8246a922.js";
116
+ /**
117
+ * The Stytch B2B IDP component.
118
+ * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
119
+ * Requires the user to be logged in.
120
+ * This component can only be used with a {@link StytchB2BUIClient} client constructor
121
+ * passed into the {@link StytchB2BProvider}
122
+ *
123
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
124
+ *
125
+ * @example
126
+ * const styles = {
127
+ * container: {
128
+ * backgroundColor: '#e11e1e',
129
+ * },
130
+ * colors: {
131
+ * primary: '#ff00f7',
132
+ * secondary: '#5C727D',
133
+ * },
134
+ * }
135
+ *
136
+ * <B2BIdentityProvider
137
+ * styles={styles}
138
+ * callbacks={{
139
+ * onEvent: (event) => console.log(event)
140
+ * }}
141
+ * />
142
+ *
143
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
144
+ * @param callbacks - An optional {@link Callbacks} object
145
+ * @param getIDPConsentManifest - Optional {@link B2BIDPConsentManifestGenerator} to customize the consent screen.
146
+ */
147
+ declare const B2BIdentityProvider: ({ styles, callbacks, getIDPConsentManifest }: B2BIdentityProviderProps) => React.JSX.Element;
148
+ export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, useStytchIsAuthorized, useStytchOrganization, withStytchB2BClient, withStytchMemberSession, withStytchMember, withStytchOrganization, withStytchPermissions } from "../StytchB2BContext-156a7bdd.js";
149
+ export { StytchB2B, B2BIdentityProvider };
150
+ export type { StytchB2BProviderProps } from "../StytchB2BContext-156a7bdd.js";
@@ -1,6 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import React from "react";
3
3
  import { Callbacks, StyleConfig, StytchB2BUIConfig, StytchProjectConfigurationInput } from "@stytch/vanilla-js";
4
+ // We need to import the StytchB2BUIClient type to give the TSDoc parser a hint as to where it is from
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+ import { IDPConsentScreenManifest } from "@stytch/vanilla-js/b2b";
4
7
  interface StytchB2BProps<TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration> {
5
8
  /**
6
9
  * An optional {@link StyleConfig} to customize the look and feel of the screen.
@@ -68,6 +71,13 @@ interface StytchB2BProps<TProjectConfiguration extends StytchProjectConfiguratio
68
71
  */
69
72
  config: StytchB2BUIConfig;
70
73
  }
74
+ type B2BIDPConsentManifestGenerator = (input: {
75
+ scopes: string[];
76
+ clientName: string;
77
+ }) => IDPConsentScreenManifest;
78
+ type B2BIdentityProviderProps = Omit<StytchB2BProps, "config"> & {
79
+ getIDPConsentManifest?: B2BIDPConsentManifestGenerator;
80
+ };
71
81
  /**
72
82
  * The Stytch B2B UI component.
73
83
  * This component can only be used with a {@link StytchB2BUIClient} client constructor
@@ -103,6 +113,38 @@ interface StytchB2BProps<TProjectConfiguration extends StytchProjectConfiguratio
103
113
  * @param props {@link StytchB2BProps}
104
114
  */
105
115
  declare const StytchB2B: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>({ styles, callbacks, config }: StytchB2BProps<TProjectConfiguration>) => React.JSX.Element;
106
- export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, useStytchIsAuthorized, useStytchOrganization, withStytchB2BClient, withStytchMemberSession, withStytchMember, withStytchOrganization, withStytchPermissions } from "../StytchB2BContext-72d99610.js";
107
- export { StytchB2B };
108
- export type { StytchB2BProviderProps } from "../StytchB2BContext-72d99610.js";
116
+ /**
117
+ * The Stytch B2B IDP component.
118
+ * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
119
+ * Requires the user to be logged in.
120
+ * This component can only be used with a {@link StytchB2BUIClient} client constructor
121
+ * passed into the {@link StytchB2BProvider}
122
+ *
123
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
124
+ *
125
+ * @example
126
+ * const styles = {
127
+ * container: {
128
+ * backgroundColor: '#e11e1e',
129
+ * },
130
+ * colors: {
131
+ * primary: '#ff00f7',
132
+ * secondary: '#5C727D',
133
+ * },
134
+ * }
135
+ *
136
+ * <B2BIdentityProvider
137
+ * styles={styles}
138
+ * callbacks={{
139
+ * onEvent: (event) => console.log(event)
140
+ * }}
141
+ * />
142
+ *
143
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
144
+ * @param callbacks - An optional {@link Callbacks} object
145
+ * @param getIDPConsentManifest - Optional {@link B2BIDPConsentManifestGenerator} to customize the consent screen.
146
+ */
147
+ declare const B2BIdentityProvider: ({ styles, callbacks, getIDPConsentManifest }: B2BIdentityProviderProps) => React.JSX.Element;
148
+ export { StytchB2BProvider, useStytchB2BClient, useStytchMemberSession, useStytchMember, useStytchIsAuthorized, useStytchOrganization, withStytchB2BClient, withStytchMemberSession, withStytchMember, withStytchOrganization, withStytchPermissions } from "../StytchB2BContext-03d66270.js";
149
+ export { StytchB2B, B2BIdentityProvider };
150
+ export type { StytchB2BProviderProps } from "../StytchB2BContext-03d66270.js";
@@ -1,7 +1,7 @@
1
- import { u as useIsMounted__INTERNAL, a as useStytchB2BClient, i as isUIClient } from '../StytchB2BContext-72d99610.js';
2
- export { S as StytchB2BProvider, a as useStytchB2BClient, d as useStytchIsAuthorized, c as useStytchMember, b as useStytchMemberSession, e as useStytchOrganization, w as withStytchB2BClient, g as withStytchMember, f as withStytchMemberSession, h as withStytchOrganization, j as withStytchPermissions } from '../StytchB2BContext-72d99610.js';
3
- import React, { useRef, useLayoutEffect } from 'react';
4
- import { i as invariant } from '../async-b1e10055.js';
1
+ import { u as useIsMounted__INTERNAL, a as useStytchB2BClient, i as isUIClient, b as useStytchMember } from '../StytchB2BContext-03d66270.js';
2
+ export { S as StytchB2BProvider, a as useStytchB2BClient, d as useStytchIsAuthorized, b as useStytchMember, c as useStytchMemberSession, e as useStytchOrganization, w as withStytchB2BClient, g as withStytchMember, f as withStytchMemberSession, h as withStytchOrganization, j as withStytchPermissions } from '../StytchB2BContext-03d66270.js';
3
+ import React, { useRef } from 'react';
4
+ import { i as invariant, a as useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect-8da8c061.js';
5
5
  import { a as noHeadlessClientError, n as noProviderError } from '../StytchSSRProxy-14916009.js';
6
6
 
7
7
  /**
@@ -42,7 +42,7 @@ const StytchB2B = ({ styles, callbacks, config, }) => {
42
42
  invariant(useIsMounted__INTERNAL(), noProviderError('<StytchB2B />', 'StytchB2BProvider'));
43
43
  const stytchClient = useStytchB2BClient();
44
44
  const containerEl = useRef(null);
45
- useLayoutEffect(() => {
45
+ useIsomorphicLayoutEffect(() => {
46
46
  if (!isUIClient(stytchClient)) {
47
47
  throw Error(noHeadlessClientError);
48
48
  }
@@ -63,5 +63,61 @@ const StytchB2B = ({ styles, callbacks, config, }) => {
63
63
  }, [stytchClient, styles, callbacks]);
64
64
  return React.createElement("div", { ref: containerEl });
65
65
  };
66
+ /**
67
+ * The Stytch B2B IDP component.
68
+ * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
69
+ * Requires the user to be logged in.
70
+ * This component can only be used with a {@link StytchB2BUIClient} client constructor
71
+ * passed into the {@link StytchB2BProvider}
72
+ *
73
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
74
+ *
75
+ * @example
76
+ * const styles = {
77
+ * container: {
78
+ * backgroundColor: '#e11e1e',
79
+ * },
80
+ * colors: {
81
+ * primary: '#ff00f7',
82
+ * secondary: '#5C727D',
83
+ * },
84
+ * }
85
+ *
86
+ * <B2BIdentityProvider
87
+ * styles={styles}
88
+ * callbacks={{
89
+ * onEvent: (event) => console.log(event)
90
+ * }}
91
+ * />
92
+ *
93
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
94
+ * @param callbacks - An optional {@link Callbacks} object
95
+ * @param getIDPConsentManifest - Optional {@link B2BIDPConsentManifestGenerator} to customize the consent screen.
96
+ */
97
+ const B2BIdentityProvider = ({ styles, callbacks, getIDPConsentManifest }) => {
98
+ invariant(useIsMounted__INTERNAL(), noProviderError('<IdentityProvider />'));
99
+ const stytchClient = useStytchB2BClient();
100
+ const containerEl = useRef(null);
101
+ const { member } = useStytchMember();
102
+ useIsomorphicLayoutEffect(() => {
103
+ if (!isUIClient(stytchClient)) {
104
+ throw Error(noHeadlessClientError);
105
+ }
106
+ if (!containerEl.current) {
107
+ return;
108
+ }
109
+ if (!containerEl.current.id) {
110
+ const randId = Math.floor(Math.random() * 1e6);
111
+ containerEl.current.id = `stytch-b2b-idp-${randId}`;
112
+ }
113
+ stytchClient.mountIdentityProvider({
114
+ callbacks,
115
+ elementId: `#${containerEl.current.id}`,
116
+ styles,
117
+ getIDPConsentManifest,
118
+ });
119
+ }, [stytchClient, styles, callbacks, member, getIDPConsentManifest]);
120
+ return React.createElement("div", { ref: containerEl });
121
+ };
66
122
 
67
- export { StytchB2B };
123
+ export { B2BIdentityProvider, StytchB2B };
package/dist/b2b/index.js CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var StytchB2BContext = require('../StytchB2BContext-8246a922.js');
5
+ var StytchB2BContext = require('../StytchB2BContext-156a7bdd.js');
6
6
  var React = require('react');
7
- var async = require('../async-86a7f0d6.js');
7
+ var useIsomorphicLayoutEffect = require('../useIsomorphicLayoutEffect-41b6e419.js');
8
8
  var StytchSSRProxy = require('../StytchSSRProxy-63bc6323.js');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -46,10 +46,10 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
46
46
  * @param props {@link StytchB2BProps}
47
47
  */
48
48
  const StytchB2B = ({ styles, callbacks, config, }) => {
49
- async.invariant(StytchB2BContext.useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchB2B />', 'StytchB2BProvider'));
49
+ useIsomorphicLayoutEffect.invariant(StytchB2BContext.useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchB2B />', 'StytchB2BProvider'));
50
50
  const stytchClient = StytchB2BContext.useStytchB2BClient();
51
51
  const containerEl = React.useRef(null);
52
- React.useLayoutEffect(() => {
52
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
53
53
  if (!StytchB2BContext.isUIClient(stytchClient)) {
54
54
  throw Error(StytchSSRProxy.noHeadlessClientError);
55
55
  }
@@ -70,6 +70,62 @@ const StytchB2B = ({ styles, callbacks, config, }) => {
70
70
  }, [stytchClient, styles, callbacks]);
71
71
  return React__default["default"].createElement("div", { ref: containerEl });
72
72
  };
73
+ /**
74
+ * The Stytch B2B IDP component.
75
+ * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
76
+ * Requires the user to be logged in.
77
+ * This component can only be used with a {@link StytchB2BUIClient} client constructor
78
+ * passed into the {@link StytchB2BProvider}
79
+ *
80
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
81
+ *
82
+ * @example
83
+ * const styles = {
84
+ * container: {
85
+ * backgroundColor: '#e11e1e',
86
+ * },
87
+ * colors: {
88
+ * primary: '#ff00f7',
89
+ * secondary: '#5C727D',
90
+ * },
91
+ * }
92
+ *
93
+ * <B2BIdentityProvider
94
+ * styles={styles}
95
+ * callbacks={{
96
+ * onEvent: (event) => console.log(event)
97
+ * }}
98
+ * />
99
+ *
100
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
101
+ * @param callbacks - An optional {@link Callbacks} object
102
+ * @param getIDPConsentManifest - Optional {@link B2BIDPConsentManifestGenerator} to customize the consent screen.
103
+ */
104
+ const B2BIdentityProvider = ({ styles, callbacks, getIDPConsentManifest }) => {
105
+ useIsomorphicLayoutEffect.invariant(StytchB2BContext.useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<IdentityProvider />'));
106
+ const stytchClient = StytchB2BContext.useStytchB2BClient();
107
+ const containerEl = React.useRef(null);
108
+ const { member } = StytchB2BContext.useStytchMember();
109
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
110
+ if (!StytchB2BContext.isUIClient(stytchClient)) {
111
+ throw Error(StytchSSRProxy.noHeadlessClientError);
112
+ }
113
+ if (!containerEl.current) {
114
+ return;
115
+ }
116
+ if (!containerEl.current.id) {
117
+ const randId = Math.floor(Math.random() * 1e6);
118
+ containerEl.current.id = `stytch-b2b-idp-${randId}`;
119
+ }
120
+ stytchClient.mountIdentityProvider({
121
+ callbacks,
122
+ elementId: `#${containerEl.current.id}`,
123
+ styles,
124
+ getIDPConsentManifest,
125
+ });
126
+ }, [stytchClient, styles, callbacks, member, getIDPConsentManifest]);
127
+ return React__default["default"].createElement("div", { ref: containerEl });
128
+ };
73
129
 
74
130
  exports.StytchB2BProvider = StytchB2BContext.StytchB2BProvider;
75
131
  exports.useStytchB2BClient = StytchB2BContext.useStytchB2BClient;
@@ -82,4 +138,5 @@ exports.withStytchMember = StytchB2BContext.withStytchMember;
82
138
  exports.withStytchMemberSession = StytchB2BContext.withStytchMemberSession;
83
139
  exports.withStytchOrganization = StytchB2BContext.withStytchOrganization;
84
140
  exports.withStytchPermissions = StytchB2BContext.withStytchPermissions;
141
+ exports.B2BIdentityProvider = B2BIdentityProvider;
85
142
  exports.StytchB2B = StytchB2B;
@@ -1,2 +1,2 @@
1
1
  export { createDeepEqual } from "./createDeepEqual-5555f2e1.js";
2
- export { mergeWithStableProps } from "./async-b1e10055.js";
2
+ export { mergeWithStableProps } from "./useIsomorphicLayoutEffect-8da8c061.js";
package/dist/index.d.ts CHANGED
@@ -171,7 +171,6 @@ interface StytchProps<TProjectConfiguration extends StytchProjectConfigurationIn
171
171
  * in your `_app.jsx` file.
172
172
  *
173
173
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
174
- * and {@link https://storybook.stytch.com interactive examples} for more.
175
174
  *
176
175
  * @example
177
176
  * <StytchLogin
@@ -203,13 +202,13 @@ declare const StytchLogin: <TProjectConfiguration extends Partial<import("@stytc
203
202
  interface StytchResetPasswordProps<TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration> extends StytchProps<TProjectConfiguration> {
204
203
  passwordResetToken: string;
205
204
  }
205
+ type IdentityProviderProps = Omit<StytchProps, "config">;
206
206
  /**
207
207
  * The Stytch Reset Password component.
208
208
  * This component can only be used with a {@link StytchUIClient} client constructor
209
209
  * passed into the {@link StytchProvider}
210
210
  *
211
211
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
212
- * and {@link https://storybook.stytch.com interactive examples} for more.
213
212
  *
214
213
  * @example
215
214
  * <StytchPasswordReset
@@ -246,7 +245,6 @@ declare const StytchPasswordReset: <TProjectConfiguration extends Partial<import
246
245
  * passed into the {@link StytchProvider}
247
246
  *
248
247
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
249
- * and {@link https://storybook.stytch.com interactive examples} for more.
250
248
  *
251
249
  * @example
252
250
  * const styles = {
@@ -271,5 +269,37 @@ declare const StytchPasswordReset: <TProjectConfiguration extends Partial<import
271
269
  * @param callbacks - An optional {@link Callbacks} object
272
270
  */
273
271
  declare const StytchPasskeyRegistration: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>({ config, styles, callbacks }: StytchProps<TProjectConfiguration>) => React.JSX.Element;
274
- export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin, StytchPasswordReset, StytchPasskeyRegistration };
272
+ /**
273
+ * The Stytch IDP component.
274
+ * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
275
+ * Requires the user to be logged in.
276
+ * This component can only be used with a {@link StytchUIClient} client constructor
277
+ * passed into the {@link StytchProvider}
278
+ *
279
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
280
+ *
281
+ * @example
282
+ * const styles = {
283
+ * container: {
284
+ * backgroundColor: '#e11e1e',
285
+ * },
286
+ * colors: {
287
+ * primary: '#ff00f7',
288
+ * secondary: '#5C727D',
289
+ * },
290
+ * }
291
+ *
292
+ * <IdentityProvider
293
+ * styles={styles}
294
+ * callbacks={{
295
+ * onEvent: (event) => console.log(event)
296
+ * }}
297
+ * />
298
+ * />
299
+ *
300
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
301
+ * @param callbacks - An optional {@link Callbacks} object
302
+ */
303
+ declare const IdentityProvider: ({ styles, callbacks }: IdentityProviderProps) => React.JSX.Element;
304
+ export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin, StytchPasswordReset, StytchPasskeyRegistration, IdentityProvider };
275
305
  export type { StytchProviderProps };
@@ -171,7 +171,6 @@ interface StytchProps<TProjectConfiguration extends StytchProjectConfigurationIn
171
171
  * in your `_app.jsx` file.
172
172
  *
173
173
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
174
- * and {@link https://storybook.stytch.com interactive examples} for more.
175
174
  *
176
175
  * @example
177
176
  * <StytchLogin
@@ -203,13 +202,13 @@ declare const StytchLogin: <TProjectConfiguration extends Partial<import("@stytc
203
202
  interface StytchResetPasswordProps<TProjectConfiguration extends StytchProjectConfigurationInput = Stytch.DefaultProjectConfiguration> extends StytchProps<TProjectConfiguration> {
204
203
  passwordResetToken: string;
205
204
  }
205
+ type IdentityProviderProps = Omit<StytchProps, "config">;
206
206
  /**
207
207
  * The Stytch Reset Password component.
208
208
  * This component can only be used with a {@link StytchUIClient} client constructor
209
209
  * passed into the {@link StytchProvider}
210
210
  *
211
211
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
212
- * and {@link https://storybook.stytch.com interactive examples} for more.
213
212
  *
214
213
  * @example
215
214
  * <StytchPasswordReset
@@ -246,7 +245,6 @@ declare const StytchPasswordReset: <TProjectConfiguration extends Partial<import
246
245
  * passed into the {@link StytchProvider}
247
246
  *
248
247
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
249
- * and {@link https://storybook.stytch.com interactive examples} for more.
250
248
  *
251
249
  * @example
252
250
  * const styles = {
@@ -271,5 +269,37 @@ declare const StytchPasswordReset: <TProjectConfiguration extends Partial<import
271
269
  * @param callbacks - An optional {@link Callbacks} object
272
270
  */
273
271
  declare const StytchPasskeyRegistration: <TProjectConfiguration extends Partial<import("@stytch/core/public").StytchProjectConfiguration> = Stytch.DefaultProjectConfiguration>({ config, styles, callbacks }: StytchProps<TProjectConfiguration>) => React.JSX.Element;
274
- export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin, StytchPasswordReset, StytchPasskeyRegistration };
272
+ /**
273
+ * The Stytch IDP component.
274
+ * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
275
+ * Requires the user to be logged in.
276
+ * This component can only be used with a {@link StytchUIClient} client constructor
277
+ * passed into the {@link StytchProvider}
278
+ *
279
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
280
+ *
281
+ * @example
282
+ * const styles = {
283
+ * container: {
284
+ * backgroundColor: '#e11e1e',
285
+ * },
286
+ * colors: {
287
+ * primary: '#ff00f7',
288
+ * secondary: '#5C727D',
289
+ * },
290
+ * }
291
+ *
292
+ * <IdentityProvider
293
+ * styles={styles}
294
+ * callbacks={{
295
+ * onEvent: (event) => console.log(event)
296
+ * }}
297
+ * />
298
+ * />
299
+ *
300
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
301
+ * @param callbacks - An optional {@link Callbacks} object
302
+ */
303
+ declare const IdentityProvider: ({ styles, callbacks }: IdentityProviderProps) => React.JSX.Element;
304
+ export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin, StytchPasswordReset, StytchPasskeyRegistration, IdentityProvider };
275
305
  export type { StytchProviderProps };
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
- import React, { createContext, useContext, useMemo, useEffect, useLayoutEffect, useRef } from 'react';
1
+ import React, { createContext, useContext, useMemo, useEffect, useRef } from 'react';
2
2
  import { i as isStytchSSRProxy, n as noProviderError, a as noHeadlessClientError } from './StytchSSRProxy-14916009.js';
3
- import { i as invariant, u as useAsyncState, m as mergeWithStableProps } from './async-b1e10055.js';
3
+ import { i as invariant, u as useAsyncState, m as mergeWithStableProps, a as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect-8da8c061.js';
4
4
 
5
5
  const initialUser = {
6
6
  user: null,
@@ -138,16 +138,12 @@ const StytchProvider = ({ stytch, children, }) => {
138
138
  React.createElement(StytchSessionContext.Provider, { value: session }, children))));
139
139
  };
140
140
 
141
- // cc https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
142
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
143
-
144
141
  /**
145
142
  * The Stytch Login Screen component.
146
143
  * This component can only be used with the Stytch UI Client - use {@link createStytchUIClient}
147
144
  * in your `_app.jsx` file.
148
145
  *
149
146
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
150
- * and {@link https://storybook.stytch.com interactive examples} for more.
151
147
  *
152
148
  * @example
153
149
  * <StytchLogin
@@ -205,7 +201,6 @@ const StytchLogin = ({ config, styles, callbacks, }) => {
205
201
  * passed into the {@link StytchProvider}
206
202
  *
207
203
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
208
- * and {@link https://storybook.stytch.com interactive examples} for more.
209
204
  *
210
205
  * @example
211
206
  * <StytchPasswordReset
@@ -268,7 +263,6 @@ const StytchPasswordReset = ({ config, styles, callbacks, passwordResetToken, })
268
263
  * passed into the {@link StytchProvider}
269
264
  *
270
265
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
271
- * and {@link https://storybook.stytch.com interactive examples} for more.
272
266
  *
273
267
  * @example
274
268
  * const styles = {
@@ -317,5 +311,60 @@ const StytchPasskeyRegistration = ({ config, styles, callbacks, }) => {
317
311
  }, [stytchClient, config, styles, callbacks, user]);
318
312
  return React.createElement("div", { ref: containerEl });
319
313
  };
314
+ /**
315
+ * The Stytch IDP component.
316
+ * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
317
+ * Requires the user to be logged in.
318
+ * This component can only be used with a {@link StytchUIClient} client constructor
319
+ * passed into the {@link StytchProvider}
320
+ *
321
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
322
+ *
323
+ * @example
324
+ * const styles = {
325
+ * container: {
326
+ * backgroundColor: '#e11e1e',
327
+ * },
328
+ * colors: {
329
+ * primary: '#ff00f7',
330
+ * secondary: '#5C727D',
331
+ * },
332
+ * }
333
+ *
334
+ * <IdentityProvider
335
+ * styles={styles}
336
+ * callbacks={{
337
+ * onEvent: (event) => console.log(event)
338
+ * }}
339
+ * />
340
+ * />
341
+ *
342
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
343
+ * @param callbacks - An optional {@link Callbacks} object
344
+ */
345
+ const IdentityProvider = ({ styles, callbacks }) => {
346
+ invariant(useIsMounted__INTERNAL(), noProviderError('<IdentityProvider />'));
347
+ const stytchClient = useStytch();
348
+ const containerEl = useRef(null);
349
+ const user = useStytchUser();
350
+ useIsomorphicLayoutEffect(() => {
351
+ if (!isUIClient(stytchClient)) {
352
+ throw Error(noHeadlessClientError);
353
+ }
354
+ if (!containerEl.current) {
355
+ return;
356
+ }
357
+ if (!containerEl.current.id) {
358
+ const randId = Math.floor(Math.random() * 1e6);
359
+ containerEl.current.id = `stytch-idp-${randId}`;
360
+ }
361
+ stytchClient.mountIdentityProvider({
362
+ callbacks,
363
+ elementId: `#${containerEl.current.id}`,
364
+ styles,
365
+ });
366
+ }, [stytchClient, styles, callbacks, user]);
367
+ return React.createElement("div", { ref: containerEl });
368
+ };
320
369
 
321
- export { StytchLogin, StytchPasskeyRegistration, StytchPasswordReset, StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser };
370
+ export { IdentityProvider, StytchLogin, StytchPasskeyRegistration, StytchPasswordReset, StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser };
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
  var StytchSSRProxy = require('./StytchSSRProxy-63bc6323.js');
7
- var async = require('./async-86a7f0d6.js');
7
+ var useIsomorphicLayoutEffect = require('./useIsomorphicLayoutEffect-41b6e419.js');
8
8
 
9
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
10
 
@@ -41,7 +41,7 @@ const isUIClient = (client) => {
41
41
  * return (<h1>Welcome, {user.name.first_name}</h1>);
42
42
  */
43
43
  const useStytchUser = () => {
44
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchUser'));
44
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchUser'));
45
45
  return React.useContext(StytchUserContext);
46
46
  };
47
47
  /**
@@ -62,7 +62,7 @@ const useStytchUser = () => {
62
62
  * }, [session, isInitialized]);
63
63
  */
64
64
  const useStytchSession = () => {
65
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchSession'));
65
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('useStytchSession'));
66
66
  return React.useContext(StytchSessionContext);
67
67
  };
68
68
  /**
@@ -76,12 +76,12 @@ const useStytchSession = () => {
76
76
  */
77
77
  const useStytch = () => {
78
78
  const ctx = React.useContext(StytchContext);
79
- async.invariant(ctx.isMounted, StytchSSRProxy.noProviderError('useStytch'));
79
+ useIsomorphicLayoutEffect.invariant(ctx.isMounted, StytchSSRProxy.noProviderError('useStytch'));
80
80
  return ctx.client;
81
81
  };
82
82
  const withStytch = (Component) => {
83
83
  const WithStytch = (props) => {
84
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytch'));
84
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytch'));
85
85
  return React__default["default"].createElement(Component, Object.assign({}, props, { stytch: useStytch() }));
86
86
  };
87
87
  WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;
@@ -89,7 +89,7 @@ const withStytch = (Component) => {
89
89
  };
90
90
  const withStytchUser = (Component) => {
91
91
  const WithStytchUser = (props) => {
92
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchUser'));
92
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchUser'));
93
93
  const { user, isInitialized, fromCache } = useStytchUser();
94
94
  return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchUser: user, stytchUserIsInitialized: isInitialized, stytchUserIsFromCache: fromCache })));
95
95
  };
@@ -98,7 +98,7 @@ const withStytchUser = (Component) => {
98
98
  };
99
99
  const withStytchSession = (Component) => {
100
100
  const WithStytchSession = (props) => {
101
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchSession'));
101
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('withStytchSession'));
102
102
  const { session, isInitialized, fromCache } = useStytchSession();
103
103
  return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchSession: session, stytchSessionIsInitialized: isInitialized, stytchSessionIsFromCache: fromCache })));
104
104
  };
@@ -119,7 +119,7 @@ const withStytchSession = (Component) => {
119
119
  */
120
120
  const StytchProvider = ({ stytch, children, }) => {
121
121
  const ctx = React.useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);
122
- const [{ user, session }, setClientState] = async.useAsyncState({
122
+ const [{ user, session }, setClientState] = useIsomorphicLayoutEffect.useAsyncState({
123
123
  session: initialSession,
124
124
  user: initialUser,
125
125
  });
@@ -137,7 +137,7 @@ const StytchProvider = ({ stytch, children, }) => {
137
137
  session: Object.assign(Object.assign({}, stytch.session.getInfo()), { isInitialized: true }),
138
138
  user: Object.assign(Object.assign({}, stytch.user.getInfo()), { isInitialized: true }),
139
139
  };
140
- return async.mergeWithStableProps(oldState, newState);
140
+ return useIsomorphicLayoutEffect.mergeWithStableProps(oldState, newState);
141
141
  });
142
142
  });
143
143
  }, [setClientState, stytch]);
@@ -146,16 +146,12 @@ const StytchProvider = ({ stytch, children, }) => {
146
146
  React__default["default"].createElement(StytchSessionContext.Provider, { value: session }, children))));
147
147
  };
148
148
 
149
- // cc https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
150
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
151
-
152
149
  /**
153
150
  * The Stytch Login Screen component.
154
151
  * This component can only be used with the Stytch UI Client - use {@link createStytchUIClient}
155
152
  * in your `_app.jsx` file.
156
153
  *
157
154
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
158
- * and {@link https://storybook.stytch.com interactive examples} for more.
159
155
  *
160
156
  * @example
161
157
  * <StytchLogin
@@ -184,10 +180,10 @@ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayou
184
180
  * @param callbacks - An optional {@link Callbacks} object
185
181
  */
186
182
  const StytchLogin = ({ config, styles, callbacks, }) => {
187
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchLogin />'));
183
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchLogin />'));
188
184
  const stytchClient = useStytch();
189
185
  const containerEl = React.useRef(null);
190
- useIsomorphicLayoutEffect(() => {
186
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
191
187
  if (!isUIClient(stytchClient)) {
192
188
  throw Error(StytchSSRProxy.noHeadlessClientError);
193
189
  }
@@ -213,7 +209,6 @@ const StytchLogin = ({ config, styles, callbacks, }) => {
213
209
  * passed into the {@link StytchProvider}
214
210
  *
215
211
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
216
- * and {@link https://storybook.stytch.com interactive examples} for more.
217
212
  *
218
213
  * @example
219
214
  * <StytchPasswordReset
@@ -244,10 +239,10 @@ const StytchLogin = ({ config, styles, callbacks, }) => {
244
239
  * @param callbacks - An optional {@link Callbacks} object
245
240
  */
246
241
  const StytchPasswordReset = ({ config, styles, callbacks, passwordResetToken, }) => {
247
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchResetPassword />'));
242
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchResetPassword />'));
248
243
  const stytchClient = useStytch();
249
244
  const containerEl = React.useRef(null);
250
- useIsomorphicLayoutEffect(() => {
245
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
251
246
  if (!isUIClient(stytchClient)) {
252
247
  throw Error(StytchSSRProxy.noHeadlessClientError);
253
248
  }
@@ -276,7 +271,6 @@ const StytchPasswordReset = ({ config, styles, callbacks, passwordResetToken, })
276
271
  * passed into the {@link StytchProvider}
277
272
  *
278
273
  * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
279
- * and {@link https://storybook.stytch.com interactive examples} for more.
280
274
  *
281
275
  * @example
282
276
  * const styles = {
@@ -301,11 +295,11 @@ const StytchPasswordReset = ({ config, styles, callbacks, passwordResetToken, })
301
295
  * @param callbacks - An optional {@link Callbacks} object
302
296
  */
303
297
  const StytchPasskeyRegistration = ({ config, styles, callbacks, }) => {
304
- async.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchPasskeyRegistration />'));
298
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<StytchPasskeyRegistration />'));
305
299
  const stytchClient = useStytch();
306
300
  const containerEl = React.useRef(null);
307
301
  const user = useStytchUser();
308
- useIsomorphicLayoutEffect(() => {
302
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
309
303
  if (!isUIClient(stytchClient)) {
310
304
  throw Error(StytchSSRProxy.noHeadlessClientError);
311
305
  }
@@ -325,7 +319,63 @@ const StytchPasskeyRegistration = ({ config, styles, callbacks, }) => {
325
319
  }, [stytchClient, config, styles, callbacks, user]);
326
320
  return React__default["default"].createElement("div", { ref: containerEl });
327
321
  };
322
+ /**
323
+ * The Stytch IDP component.
324
+ * Parses OAuth Authorization params (client_id, scope, nonce, etc.) out of the page URL.
325
+ * Requires the user to be logged in.
326
+ * This component can only be used with a {@link StytchUIClient} client constructor
327
+ * passed into the {@link StytchProvider}
328
+ *
329
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
330
+ *
331
+ * @example
332
+ * const styles = {
333
+ * container: {
334
+ * backgroundColor: '#e11e1e',
335
+ * },
336
+ * colors: {
337
+ * primary: '#ff00f7',
338
+ * secondary: '#5C727D',
339
+ * },
340
+ * }
341
+ *
342
+ * <IdentityProvider
343
+ * styles={styles}
344
+ * callbacks={{
345
+ * onEvent: (event) => console.log(event)
346
+ * }}
347
+ * />
348
+ * />
349
+ *
350
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
351
+ * @param callbacks - An optional {@link Callbacks} object
352
+ */
353
+ const IdentityProvider = ({ styles, callbacks }) => {
354
+ useIsomorphicLayoutEffect.invariant(useIsMounted__INTERNAL(), StytchSSRProxy.noProviderError('<IdentityProvider />'));
355
+ const stytchClient = useStytch();
356
+ const containerEl = React.useRef(null);
357
+ const user = useStytchUser();
358
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
359
+ if (!isUIClient(stytchClient)) {
360
+ throw Error(StytchSSRProxy.noHeadlessClientError);
361
+ }
362
+ if (!containerEl.current) {
363
+ return;
364
+ }
365
+ if (!containerEl.current.id) {
366
+ const randId = Math.floor(Math.random() * 1e6);
367
+ containerEl.current.id = `stytch-idp-${randId}`;
368
+ }
369
+ stytchClient.mountIdentityProvider({
370
+ callbacks,
371
+ elementId: `#${containerEl.current.id}`,
372
+ styles,
373
+ });
374
+ }, [stytchClient, styles, callbacks, user]);
375
+ return React__default["default"].createElement("div", { ref: containerEl });
376
+ };
328
377
 
378
+ exports.IdentityProvider = IdentityProvider;
329
379
  exports.StytchLogin = StytchLogin;
330
380
  exports.StytchPasskeyRegistration = StytchPasskeyRegistration;
331
381
  exports.StytchPasswordReset = StytchPasswordReset;
@@ -1,4 +1,10 @@
1
- import { Dispatch, SetStateAction } from 'react';
1
+ import { Dispatch, SetStateAction, useEffect } from "react";
2
+ // useState can cause memory leaks if it is set after the component unmounted. For example, if it is
3
+ // set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.
4
+ declare const useAsyncState: <T>(initialState: T | (() => T)) => [
5
+ T,
6
+ Dispatch<SetStateAction<T>>
7
+ ];
2
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
9
  declare function invariant(cond: any, message: string): asserts cond;
4
10
  /**
@@ -14,5 +20,5 @@ declare function invariant(cond: any, message: string): asserts cond;
14
20
  * @param newValue The new value
15
21
  */
16
22
  declare const mergeWithStableProps: <T extends Record<string, unknown>, U extends Record<string, unknown> = T>(oldValue: U, newValue: T) => T;
17
- declare const useAsyncState: <T>(initialState: T | (() => T)) => [T, Dispatch<SetStateAction<T>>];
18
- export { invariant, mergeWithStableProps, useAsyncState };
23
+ declare const useIsomorphicLayoutEffect: typeof useEffect;
24
+ export { useIsomorphicLayoutEffect as default, useAsyncState, invariant, mergeWithStableProps };
@@ -76,6 +76,10 @@ const useAsyncState = (initialState) => {
76
76
  return [state, setStateAction];
77
77
  };
78
78
 
79
+ // cc https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
80
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
81
+
79
82
  exports.invariant = invariant;
80
83
  exports.mergeWithStableProps = mergeWithStableProps;
81
84
  exports.useAsyncState = useAsyncState;
85
+ exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
@@ -1,4 +1,10 @@
1
- import { Dispatch, SetStateAction } from 'react';
1
+ import { Dispatch, SetStateAction, useEffect } from "react";
2
+ // useState can cause memory leaks if it is set after the component unmounted. For example, if it is
3
+ // set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.
4
+ declare const useAsyncState: <T>(initialState: T | (() => T)) => [
5
+ T,
6
+ Dispatch<SetStateAction<T>>
7
+ ];
2
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
9
  declare function invariant(cond: any, message: string): asserts cond;
4
10
  /**
@@ -14,5 +20,5 @@ declare function invariant(cond: any, message: string): asserts cond;
14
20
  * @param newValue The new value
15
21
  */
16
22
  declare const mergeWithStableProps: <T extends Record<string, unknown>, U extends Record<string, unknown> = T>(oldValue: U, newValue: T) => T;
17
- declare const useAsyncState: <T>(initialState: T | (() => T)) => [T, Dispatch<SetStateAction<T>>];
18
- export { invariant, mergeWithStableProps, useAsyncState };
23
+ declare const useIsomorphicLayoutEffect: typeof useEffect;
24
+ export { useIsomorphicLayoutEffect as default, useAsyncState, invariant, 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
@@ -74,4 +74,7 @@ const useAsyncState = (initialState) => {
74
74
  return [state, setStateAction];
75
75
  };
76
76
 
77
- export { invariant as i, mergeWithStableProps as m, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stytch/nextjs",
3
- "version": "21.3.0",
3
+ "version": "21.4.1",
4
4
  "description": "Stytch's official Next.js Library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -23,7 +23,7 @@
23
23
  "devDependencies": {
24
24
  "@babel/runtime": "7.18.6",
25
25
  "@stytch/js-utils": "0.0.0",
26
- "@stytch/vanilla-js": "5.16.0",
26
+ "@stytch/vanilla-js": "5.17.1",
27
27
  "@testing-library/react": "14.0.0",
28
28
  "eslint-config-custom": "0.0.1",
29
29
  "react": "18.2.0",