@stytch/nextjs 0.4.3 → 0.4.5

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 ADDED
@@ -0,0 +1,15 @@
1
+ # @stytch/nextjs
2
+
3
+ ## 0.4.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Reset Password component
8
+
9
+ ## 0.4.4
10
+
11
+ ### Patch Changes
12
+
13
+ - Send methods in the SDK
14
+ - Updated dependencies
15
+ - @stytch/vanilla-js@0.4.4
package/dist/index.d.ts CHANGED
@@ -200,5 +200,45 @@ interface StytchProps {
200
200
  * @param callbacks - An optional {@link Callbacks} object
201
201
  */
202
202
  declare const StytchLogin: ({ config, styles, callbacks }: StytchProps) => JSX.Element;
203
- export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin };
203
+ interface StytchResetPasswordProps extends StytchProps {
204
+ passwordResetToken: string;
205
+ }
206
+ /**
207
+ * The Stytch Reset Password component.
208
+ * This component can only be used with a {@link StytchUIClient} client constructor
209
+ * passed into the {@link StytchProvider}
210
+ *
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
+ *
214
+ * @example
215
+ * <StytchPasswordReset
216
+ * config={{
217
+ * products: ['emailMagicLinks', 'oauth'],
218
+ * emailMagicLinksOptions: {
219
+ * loginRedirectURL: 'https://example.com/authenticate',
220
+ * signupRedirectURL: 'https://example.com/authenticate',
221
+ * },
222
+ * oauthOptions: {
223
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
224
+ * },
225
+ * }}
226
+ * passwordResetToken="PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs"
227
+ * styles={{
228
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
229
+ * primaryColor: '#0577CA',
230
+ * width: '321px',
231
+ * }}
232
+ * callbacks={{
233
+ * onEvent: (event) => console.log(event)
234
+ * }}
235
+ * />
236
+ *
237
+ * @param config - A {@link StytchLoginConfig} object
238
+ * @param passwordResetToken - A Stytch password reset token
239
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
240
+ * @param callbacks - An optional {@link Callbacks} object
241
+ */
242
+ declare const StytchPasswordReset: ({ config, styles, callbacks, passwordResetToken }: StytchResetPasswordProps) => JSX.Element;
243
+ export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin, StytchPasswordReset };
204
244
  export type { StytchProviderProps };
@@ -200,5 +200,45 @@ interface StytchProps {
200
200
  * @param callbacks - An optional {@link Callbacks} object
201
201
  */
202
202
  declare const StytchLogin: ({ config, styles, callbacks }: StytchProps) => JSX.Element;
203
- export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin };
203
+ interface StytchResetPasswordProps extends StytchProps {
204
+ passwordResetToken: string;
205
+ }
206
+ /**
207
+ * The Stytch Reset Password component.
208
+ * This component can only be used with a {@link StytchUIClient} client constructor
209
+ * passed into the {@link StytchProvider}
210
+ *
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
+ *
214
+ * @example
215
+ * <StytchPasswordReset
216
+ * config={{
217
+ * products: ['emailMagicLinks', 'oauth'],
218
+ * emailMagicLinksOptions: {
219
+ * loginRedirectURL: 'https://example.com/authenticate',
220
+ * signupRedirectURL: 'https://example.com/authenticate',
221
+ * },
222
+ * oauthOptions: {
223
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
224
+ * },
225
+ * }}
226
+ * passwordResetToken="PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs"
227
+ * styles={{
228
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
229
+ * primaryColor: '#0577CA',
230
+ * width: '321px',
231
+ * }}
232
+ * callbacks={{
233
+ * onEvent: (event) => console.log(event)
234
+ * }}
235
+ * />
236
+ *
237
+ * @param config - A {@link StytchLoginConfig} object
238
+ * @param passwordResetToken - A Stytch password reset token
239
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
240
+ * @param callbacks - An optional {@link Callbacks} object
241
+ */
242
+ declare const StytchPasswordReset: ({ config, styles, callbacks, passwordResetToken }: StytchResetPasswordProps) => JSX.Element;
243
+ export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin, StytchPasswordReset };
204
244
  export type { StytchProviderProps };
package/dist/index.esm.js CHANGED
@@ -234,5 +234,68 @@ const StytchLogin = ({ config, styles, callbacks }) => {
234
234
  }, [stytchClient, config, styles, callbacks]);
235
235
  return React.createElement("div", { ref: containerEl });
236
236
  };
237
+ /**
238
+ * The Stytch Reset Password component.
239
+ * This component can only be used with a {@link StytchUIClient} client constructor
240
+ * passed into the {@link StytchProvider}
241
+ *
242
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
243
+ * and {@link https://storybook.stytch.com interactive examples} for more.
244
+ *
245
+ * @example
246
+ * <StytchPasswordReset
247
+ * config={{
248
+ * products: ['emailMagicLinks', 'oauth'],
249
+ * emailMagicLinksOptions: {
250
+ * loginRedirectURL: 'https://example.com/authenticate',
251
+ * signupRedirectURL: 'https://example.com/authenticate',
252
+ * },
253
+ * oauthOptions: {
254
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
255
+ * },
256
+ * }}
257
+ * passwordResetToken="PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs"
258
+ * styles={{
259
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
260
+ * primaryColor: '#0577CA',
261
+ * width: '321px',
262
+ * }}
263
+ * callbacks={{
264
+ * onEvent: (event) => console.log(event)
265
+ * }}
266
+ * />
267
+ *
268
+ * @param config - A {@link StytchLoginConfig} object
269
+ * @param passwordResetToken - A Stytch password reset token
270
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
271
+ * @param callbacks - An optional {@link Callbacks} object
272
+ */
273
+ const StytchPasswordReset = ({ config, styles, callbacks, passwordResetToken }) => {
274
+ invariant(useIsMounted__INTERNAL(), noProviderError('<StytchResetPassword />'));
275
+ const stytchClient = useStytch();
276
+ const containerEl = useRef(null);
277
+ useIsomorphicLayoutEffect(() => {
278
+ if (!isUIClient(stytchClient)) {
279
+ throw Error(noHeadlessClientError);
280
+ }
281
+ if (!containerEl.current) {
282
+ return;
283
+ }
284
+ if (!containerEl.current.id) {
285
+ const randId = Math.floor(Math.random() * 1e6);
286
+ containerEl.current.id = `stytch-reset-password-${randId}`;
287
+ }
288
+ if (passwordResetToken) {
289
+ stytchClient.mountResetPassword({
290
+ config,
291
+ callbacks,
292
+ elementId: `#${containerEl.current.id}`,
293
+ styles,
294
+ passwordResetToken,
295
+ });
296
+ }
297
+ }, [stytchClient, config, styles, callbacks, passwordResetToken]);
298
+ return React.createElement("div", { ref: containerEl });
299
+ };
237
300
 
238
- export { StytchLogin, StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser };
301
+ export { StytchLogin, StytchPasswordReset, StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser };
package/dist/index.js CHANGED
@@ -114,7 +114,7 @@ const useStytch = () => {
114
114
  const withStytch = (Component) => {
115
115
  const WithStytch = (props) => {
116
116
  invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));
117
- return React__default["default"].createElement(Component, Object.assign({}, props, { stytch: useStytch() }));
117
+ return React__default['default'].createElement(Component, Object.assign({}, props, { stytch: useStytch() }));
118
118
  };
119
119
  WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;
120
120
  return WithStytch;
@@ -123,7 +123,7 @@ const withStytchUser = (Component) => {
123
123
  const WithStytchUser = (props) => {
124
124
  invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));
125
125
  const { user, isInitialized, fromCache } = useStytchUser();
126
- return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchUser: user, stytchUserIsInitialized: isInitialized, stytchUserIsFromCache: fromCache })));
126
+ return (React__default['default'].createElement(Component, Object.assign({}, props, { stytchUser: user, stytchUserIsInitialized: isInitialized, stytchUserIsFromCache: fromCache })));
127
127
  };
128
128
  WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;
129
129
  return WithStytchUser;
@@ -132,7 +132,7 @@ const withStytchSession = (Component) => {
132
132
  const WithStytchSession = (props) => {
133
133
  invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));
134
134
  const { session, isInitialized, fromCache } = useStytchSession();
135
- return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchSession: session, stytchSessionIsInitialized: isInitialized, stytchSessionIsFromCache: fromCache })));
135
+ return (React__default['default'].createElement(Component, Object.assign({}, props, { stytchSession: session, stytchSessionIsInitialized: isInitialized, stytchSessionIsFromCache: fromCache })));
136
136
  };
137
137
  WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;
138
138
  return WithStytchSession;
@@ -176,9 +176,9 @@ const StytchProvider = ({ stytch, children }) => {
176
176
  }, [stytch, setUser, setSession]);
177
177
  const finalSess = !!session.session === !!user.user ? session : initialSession;
178
178
  const finalUser = !!session.session === !!user.user ? user : initialUser;
179
- return (React__default["default"].createElement(StytchContext.Provider, { value: ctx },
180
- React__default["default"].createElement(StytchUserContext.Provider, { value: finalUser },
181
- React__default["default"].createElement(StytchSessionContext.Provider, { value: finalSess }, children))));
179
+ return (React__default['default'].createElement(StytchContext.Provider, { value: ctx },
180
+ React__default['default'].createElement(StytchUserContext.Provider, { value: finalUser },
181
+ React__default['default'].createElement(StytchSessionContext.Provider, { value: finalSess }, children))));
182
182
  };
183
183
 
184
184
  // cc https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
@@ -240,10 +240,74 @@ const StytchLogin = ({ config, styles, callbacks }) => {
240
240
  styles,
241
241
  });
242
242
  }, [stytchClient, config, styles, callbacks]);
243
- return React__default["default"].createElement("div", { ref: containerEl });
243
+ return React__default['default'].createElement("div", { ref: containerEl });
244
+ };
245
+ /**
246
+ * The Stytch Reset Password component.
247
+ * This component can only be used with a {@link StytchUIClient} client constructor
248
+ * passed into the {@link StytchProvider}
249
+ *
250
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
251
+ * and {@link https://storybook.stytch.com interactive examples} for more.
252
+ *
253
+ * @example
254
+ * <StytchPasswordReset
255
+ * config={{
256
+ * products: ['emailMagicLinks', 'oauth'],
257
+ * emailMagicLinksOptions: {
258
+ * loginRedirectURL: 'https://example.com/authenticate',
259
+ * signupRedirectURL: 'https://example.com/authenticate',
260
+ * },
261
+ * oauthOptions: {
262
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
263
+ * },
264
+ * }}
265
+ * passwordResetToken="PvC5UudZ7TPZbELt95yXAQ-8MeEUCRob8bUQ-g52fIJs"
266
+ * styles={{
267
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
268
+ * primaryColor: '#0577CA',
269
+ * width: '321px',
270
+ * }}
271
+ * callbacks={{
272
+ * onEvent: (event) => console.log(event)
273
+ * }}
274
+ * />
275
+ *
276
+ * @param config - A {@link StytchLoginConfig} object
277
+ * @param passwordResetToken - A Stytch password reset token
278
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
279
+ * @param callbacks - An optional {@link Callbacks} object
280
+ */
281
+ const StytchPasswordReset = ({ config, styles, callbacks, passwordResetToken }) => {
282
+ invariant(useIsMounted__INTERNAL(), noProviderError('<StytchResetPassword />'));
283
+ const stytchClient = useStytch();
284
+ const containerEl = React.useRef(null);
285
+ useIsomorphicLayoutEffect(() => {
286
+ if (!isUIClient(stytchClient)) {
287
+ throw Error(noHeadlessClientError);
288
+ }
289
+ if (!containerEl.current) {
290
+ return;
291
+ }
292
+ if (!containerEl.current.id) {
293
+ const randId = Math.floor(Math.random() * 1e6);
294
+ containerEl.current.id = `stytch-reset-password-${randId}`;
295
+ }
296
+ if (passwordResetToken) {
297
+ stytchClient.mountResetPassword({
298
+ config,
299
+ callbacks,
300
+ elementId: `#${containerEl.current.id}`,
301
+ styles,
302
+ passwordResetToken,
303
+ });
304
+ }
305
+ }, [stytchClient, config, styles, callbacks, passwordResetToken]);
306
+ return React__default['default'].createElement("div", { ref: containerEl });
244
307
  };
245
308
 
246
309
  exports.StytchLogin = StytchLogin;
310
+ exports.StytchPasswordReset = StytchPasswordReset;
247
311
  exports.StytchProvider = StytchProvider;
248
312
  exports.useStytch = useStytch;
249
313
  exports.useStytchSession = useStytchSession;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stytch/nextjs",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "Stytch's official Next.js Library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -20,14 +20,14 @@
20
20
  "license": "MIT",
21
21
  "author": "Stytch",
22
22
  "devDependencies": {
23
- "@babel/runtime": "^7.18.6",
24
- "@stytch/vanilla-js": "0.3.3",
23
+ "@babel/runtime": "7.18.6",
24
+ "@stytch/vanilla-js": "0.4.4",
25
25
  "eslint-config-custom": "0.0.0",
26
- "rollup": "^2.56.3",
26
+ "rollup": "2.56.3",
27
27
  "typescript": "4.7.4"
28
28
  },
29
29
  "peerDependencies": {
30
- "@stytch/vanilla-js": "^0.3.3",
30
+ "@stytch/vanilla-js": "^0.4.4",
31
31
  "react": ">= 17.0.2",
32
32
  "react-dom": ">= 17.0.2"
33
33
  },
@@ -43,4 +43,4 @@
43
43
  "jwt",
44
44
  "user"
45
45
  ]
46
- }
46
+ }