@stytch/nextjs 0.0.2-0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,7 @@ For full documentation please refer to Stytch's javascript SDK documentation on
17
17
  import { StytchProvider } from '@stytch/nextjs';
18
18
  import { createStytchUIClient } from '@stytch/nextjs/ui';
19
19
 
20
- const stytch = new createStytchUIClient('public-token-<find yours in the stytch dashboard>');
20
+ const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>');
21
21
 
22
22
  // Wrap your App in the StytchProvider
23
23
  ReactDOM.render(
@@ -54,7 +54,7 @@ const App = () => {
54
54
 
55
55
  return (
56
56
  <div id="login">
57
- <Stytch config={stytchProps.config} styles={stytchProps.styles} callbacks={stytchProps.callbacks} />
57
+ <StytchLogin config={stytchProps.config} styles={stytchProps.styles} callbacks={stytchProps.callbacks} />
58
58
  </div>
59
59
  );
60
60
  };
@@ -63,3 +63,98 @@ const App = () => {
63
63
  ## Typescript Support
64
64
 
65
65
  There are built in typescript definitions in the npm package.
66
+
67
+ ## Migrating from @stytch/stytch-react
68
+
69
+ If you are migrating from [@stytch/stytch-react](https://www.npmjs.com/package/@stytch/stytch-react), follow the steps below:
70
+
71
+ ### Step 1: Install the new libraries
72
+
73
+ - The core SDK is now bundled in its own module - [@stytch/vanilla-js](https://www.npmjs.com/package/@stytch/vanilla-js)
74
+ - We now have a library specifically for NextJS bindings - [@stytch/nextjs](https://www.npmjs.com/package/@stytch/nextjs)
75
+
76
+ ```shell
77
+ # NPM
78
+ npm install @stytch/vanilla-js @stytch/nextjs
79
+ # Yarn
80
+ yarn add @stytch/vanilla-js @stytch/nextjs
81
+ ```
82
+
83
+ ### Step 2: Remove the old SDK
84
+
85
+ - Remove the `@stytch/stytch-react` package
86
+ - If you are explicitly loading the `stytch.js` script via a blocking `beforeInteractive` tag in the document header, remove it. It isn't needed anymore.
87
+
88
+ ```shell
89
+ # NPM
90
+ npm rm @stytch/stytch-react
91
+ # Yarn
92
+ yarn remove @stytch/stytch-react
93
+ ```
94
+
95
+ ### Step 3: Initialize the Stytch client in `_app.js`
96
+
97
+ - Determine if you need the Headless or UI client. If you plan to use the `<StytchLogin />` component in your application then you should use the the UI client. Otherwise use the Headless client to minimize application bundle size.
98
+ - To create the Stytch Headless client, use `createStytchHeadlessClient` from `@stytch/nextjs/headless`
99
+ - To create the Stytch UI client, use `createStytchUIClient` from `@stytch/nextjs/ui`
100
+ - Pass it into `<StytchProvider />` component from `@stytch/nextjs`
101
+
102
+ ```jsx
103
+ import React from 'react';
104
+ import { StytchProvider } from '@stytch/nextjs';
105
+ import { createStytchHeadlessClient } from '@stytch/nextjs/headless';
106
+ // Or alternately
107
+ // import { createStytchUIClient } from '@stytch/nextjs/ui';
108
+
109
+ const stytch = createStytchHeadlessClient(process.env.NEXT_PUBLIC_STYTCH_PUBLIC_TOKEN);
110
+
111
+ function MyApp({ Component, pageProps }) {
112
+ return (
113
+ <StytchProvider stytch={stytch}>
114
+ <Component {...pageProps} />
115
+ </StytchProvider>
116
+ );
117
+ }
118
+
119
+ export default MyApp;
120
+ ```
121
+
122
+ ### Step 4: Update calls to `useStytchUser` , `useStytchSession`, and `useStytchLazy`
123
+
124
+ - `useStytchUser` and `useStytchSession` hooks now return envelope objects - `{ user, isInitialized, isCached }` and `{ session, isInitialized, isCached }` respectively.
125
+ - In SSR/SSG contexts, as well as the first clientside render, `user`/`session` will be null and `isInitialized` will be false
126
+ - The SDK will read `user`/`session` out of persistent storage, and rerender with `isCached: true` - at this point you’re reading the [stale-while-revalidating](https://swr.vercel.app/) value
127
+ - The SDK will make network requests to pull the most up-to-date user and session objects, and serve them with `isCached: false`
128
+ - `useStytchLazy` is no longer required - you may always call `useStytch` now
129
+
130
+ ```jsx
131
+ import React, { useEffect } from 'react';
132
+ import { useRouter } from 'next/router';
133
+ import { useStytchUser } from '@stytch/nextjs';
134
+
135
+ export default function Profile() {
136
+ const router = useRouter();
137
+ const { user, isInitialized } = useStytchUser();
138
+
139
+ useEffect(() => {
140
+ if (isInitialized && user === null) {
141
+ router.push('/login');
142
+ }
143
+ }, [user, isInitialized]);
144
+
145
+ return (
146
+ <Layout>
147
+ <h1>Your Profile</h1>
148
+ <pre>{JSON.stringify(user, null, 2)}</pre>
149
+ </Layout>
150
+ );
151
+ }
152
+ ```
153
+
154
+ ### Step 5: UI Naming Changes
155
+
156
+ We've made a number of small changes to our naming conventions to make the API cleaner and easier to understand.
157
+
158
+ - The `<Stytch />` login component is now called `<StytchLogin />`
159
+ - The `OAuthProvidersTypes` enum is now called `OAuthProviders`
160
+ - The `SDKProductTypes` enum is now called `Products`
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import React from "react";
3
3
  import { ReactNode } from "react";
4
- import { User, Session, StytchUIClient, Callbacks, Config } from "@stytch/vanilla-js";
4
+ import { User, Session, StytchUIClient, Callbacks, StytchLoginConfig, StyleConfig } from "@stytch/vanilla-js";
5
5
  import { StytchHeadlessClient } from "@stytch/vanilla-js/headless";
6
6
  /**
7
- * TODO: How much of this package can be reused from stytch-react?
7
+ * The Stytch Client object passed in to <StytchProvider /> in your `_app.js`.
8
+ * Either a StytchUIClient or StytchHeadlessClient.
8
9
  */
9
10
  type StytchClient = StytchUIClient | StytchHeadlessClient;
10
11
  type SWRUser = {
@@ -13,11 +14,7 @@ type SWRUser = {
13
14
  isInitialized: false;
14
15
  } | {
15
16
  user: User | null;
16
- fromCache: true;
17
- isInitialized: true;
18
- } | {
19
- user: User | null;
20
- fromCache: false;
17
+ fromCache: boolean;
21
18
  isInitialized: true;
22
19
  };
23
20
  type SWRSession = {
@@ -26,15 +23,50 @@ type SWRSession = {
26
23
  isInitialized: false;
27
24
  } | {
28
25
  session: Session | null;
29
- fromCache: true;
30
- isInitialized: true;
31
- } | {
32
- session: Session | null;
33
- fromCache: false;
26
+ fromCache: boolean;
34
27
  isInitialized: true;
35
28
  };
29
+ /**
30
+ * Returns the active User.
31
+ * The Stytch SDKs are used for client-side authentication and session management.
32
+ * Check the isInitialized property to determine if the SDK has completed initialization.
33
+ * Check the fromCache property to determine if the session data is from persistent storage.
34
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
35
+ * @example
36
+ * const {user, isInitialized, fromCache} = useStytchUser();
37
+ * if (!isInitialized) {
38
+ * return <p>Loading...</p>;
39
+ * }
40
+ * return (<h1>Welcome, {user.name.first_name}</h1>);
41
+ */
36
42
  declare const useStytchUser: () => SWRUser;
43
+ /**
44
+ * Returns the user's active Stytch session.
45
+ * The Stytch SDKs are used for client-side authentication and session management.
46
+ * Check the isInitialized property to determine if the SDK has completed initialization.
47
+ * Check the fromCache property to determine if the session data is from persistent storage.
48
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
49
+ * @example
50
+ * const {session, isInitialized, fromCache} = useStytchSession();
51
+ * useEffect(() => {
52
+ * if (!isInitialized) {
53
+ * return;
54
+ * }
55
+ * if (!session) {
56
+ * router.replace('/login')
57
+ * }
58
+ * }, [session, isInitialized]);
59
+ */
37
60
  declare const useStytchSession: () => SWRSession;
61
+ /**
62
+ * Returns the Stytch client stored in the Stytch context.
63
+ *
64
+ * @example
65
+ * const stytch = useStytch();
66
+ * useEffect(() => {
67
+ * stytch.magicLinks.authenticate('...')
68
+ * }, [stytch]);
69
+ */
38
70
  declare const useStytch: () => StytchClient;
39
71
  declare const withStytch: <T extends object>(Component: React.ComponentType<T & {
40
72
  stytch: StytchClient;
@@ -49,29 +81,124 @@ declare const withStytchSession: <T extends object>(Component: React.ComponentTy
49
81
  stytchSessionIsInitialized: boolean;
50
82
  stytchSessionIsFromCache: boolean;
51
83
  }>) => React.ComponentType<T>;
52
- type StytchProviderProps = {
84
+ interface StytchProviderProps {
85
+ /**
86
+ * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchUIClient}
87
+ */
53
88
  stytch: StytchClient;
54
89
  children?: ReactNode;
55
- };
90
+ }
91
+ /**
92
+ * The Stytch Context Provider.
93
+ * Wrap your application with this component in `_app.js` in order to use Stytch everywhere in your app.
94
+ * @example
95
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
96
+ *
97
+ * return (
98
+ * <StytchProvider stytch={stytch}>
99
+ * <App />
100
+ * </StytchProvider>
101
+ * )
102
+ */
56
103
  declare const StytchProvider: ({ stytch, children }: StytchProviderProps) => JSX.Element;
104
+ interface StytchProps {
105
+ /**
106
+ * A {@link StytchLoginConfig} object. Add products and product-specific config to this object to change the login methods shown.
107
+ *
108
+ * @example
109
+ * {
110
+ * products: ['crypto', 'otps']
111
+ * }
112
+ *
113
+ * @example
114
+ * {
115
+ * products: ['emailMagicLinks'>]
116
+ * emailMagicLinksOptions: {
117
+ * loginRedirectURL: 'https://example.com/authenticate',
118
+ * signupRedirectURL: 'https://example.com/authenticate',
119
+ * }
120
+ * }
121
+ *
122
+ * @example
123
+ * {
124
+ * products: ['oauth'>]
125
+ * oauthOptions: {
126
+ * providers: [
127
+ * { type: 'google', one_tap: true, position: 'embedded' },
128
+ * { type: 'microsoft' },
129
+ * { type: 'apple' },
130
+ * { type: 'facebook' },
131
+ * ],
132
+ * }
133
+ * }
134
+ */
135
+ config: StytchLoginConfig;
136
+ /**
137
+ * An optional {@link StyleConfig} to customize the look and feel of the screen.
138
+ *
139
+ * @example
140
+ * {
141
+ * fontFamily: 'Arial, Helvetica, sans-serif',
142
+ * width: '360px',
143
+ * primaryColor: '#19303D',
144
+ * }
145
+ */
146
+ styles?: StyleConfig;
147
+ /**
148
+ * An optional {@link Callbacks} object.
149
+ *
150
+ * @example
151
+ * {
152
+ * onError: ({message}) => {
153
+ * console.error('Stytch login screen error', message)
154
+ * }
155
+ * }
156
+ *
157
+ * @example
158
+ * {
159
+ * onEvent: ({type, data}) => {
160
+ * if(type === StytchEventType.CryptoWalletAuthenticate) {
161
+ * console.log('Logged in with crypto wallet', data);
162
+ * }
163
+ * }
164
+ * }
165
+ */
166
+ callbacks?: Callbacks;
167
+ }
57
168
  /**
58
- * Stytch JS React Component
169
+ * The Stytch Login Screen component.
170
+ * This component can only be used with the Stytch UI Client - use {@link createStytchUIClient}
171
+ * in your `_app.jsx` file.
172
+ *
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
+ *
176
+ * @example
177
+ * <StytchLogin
178
+ * config={{
179
+ * products: ['emailMagicLinks', 'oauth'],
180
+ * emailMagicLinksOptions: {
181
+ * loginRedirectURL: 'https://example.com/authenticate',
182
+ * signupRedirectURL: 'https://example.com/authenticate',
183
+ * },
184
+ * oauthOptions: {
185
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
186
+ * },
187
+ * }}
188
+ * styles={{
189
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
190
+ * primaryColor: '#0577CA',
191
+ * width: '321px',
192
+ * }}
193
+ * callbacks={{
194
+ * onEvent: (event) => console.log(event)
195
+ * }}
196
+ * />
59
197
  *
60
- * [Documentation](https://stytch.com/docs/javascript-sdk)
198
+ * @param config - A {@link StytchLoginConfig} object
199
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
200
+ * @param callbacks - An optional {@link Callbacks} object
61
201
  */
62
- declare const Stytch: ({ config, styles, callbacks }: {
63
- config: Config;
64
- styles?: Partial<{
65
- fontFamily: string;
66
- width: string;
67
- primaryColor: string;
68
- primaryTextColor: string;
69
- secondaryTextColor: string;
70
- lightGrey: string;
71
- darkGrey: string;
72
- hideHeaderText: boolean;
73
- }> | undefined;
74
- callbacks?: Callbacks | undefined;
75
- }) => JSX.Element;
76
- export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, Stytch };
202
+ declare const StytchLogin: ({ config, styles, callbacks }: StytchProps) => JSX.Element;
203
+ export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin };
77
204
  export type { StytchProviderProps };
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import React from "react";
3
3
  import { ReactNode } from "react";
4
- import { User, Session, StytchUIClient, Callbacks, Config } from "@stytch/vanilla-js";
4
+ import { User, Session, StytchUIClient, Callbacks, StytchLoginConfig, StyleConfig } from "@stytch/vanilla-js";
5
5
  import { StytchHeadlessClient } from "@stytch/vanilla-js/headless";
6
6
  /**
7
- * TODO: How much of this package can be reused from stytch-react?
7
+ * The Stytch Client object passed in to <StytchProvider /> in your `_app.js`.
8
+ * Either a StytchUIClient or StytchHeadlessClient.
8
9
  */
9
10
  type StytchClient = StytchUIClient | StytchHeadlessClient;
10
11
  type SWRUser = {
@@ -13,11 +14,7 @@ type SWRUser = {
13
14
  isInitialized: false;
14
15
  } | {
15
16
  user: User | null;
16
- fromCache: true;
17
- isInitialized: true;
18
- } | {
19
- user: User | null;
20
- fromCache: false;
17
+ fromCache: boolean;
21
18
  isInitialized: true;
22
19
  };
23
20
  type SWRSession = {
@@ -26,15 +23,50 @@ type SWRSession = {
26
23
  isInitialized: false;
27
24
  } | {
28
25
  session: Session | null;
29
- fromCache: true;
30
- isInitialized: true;
31
- } | {
32
- session: Session | null;
33
- fromCache: false;
26
+ fromCache: boolean;
34
27
  isInitialized: true;
35
28
  };
29
+ /**
30
+ * Returns the active User.
31
+ * The Stytch SDKs are used for client-side authentication and session management.
32
+ * Check the isInitialized property to determine if the SDK has completed initialization.
33
+ * Check the fromCache property to determine if the session data is from persistent storage.
34
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
35
+ * @example
36
+ * const {user, isInitialized, fromCache} = useStytchUser();
37
+ * if (!isInitialized) {
38
+ * return <p>Loading...</p>;
39
+ * }
40
+ * return (<h1>Welcome, {user.name.first_name}</h1>);
41
+ */
36
42
  declare const useStytchUser: () => SWRUser;
43
+ /**
44
+ * Returns the user's active Stytch session.
45
+ * The Stytch SDKs are used for client-side authentication and session management.
46
+ * Check the isInitialized property to determine if the SDK has completed initialization.
47
+ * Check the fromCache property to determine if the session data is from persistent storage.
48
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
49
+ * @example
50
+ * const {session, isInitialized, fromCache} = useStytchSession();
51
+ * useEffect(() => {
52
+ * if (!isInitialized) {
53
+ * return;
54
+ * }
55
+ * if (!session) {
56
+ * router.replace('/login')
57
+ * }
58
+ * }, [session, isInitialized]);
59
+ */
37
60
  declare const useStytchSession: () => SWRSession;
61
+ /**
62
+ * Returns the Stytch client stored in the Stytch context.
63
+ *
64
+ * @example
65
+ * const stytch = useStytch();
66
+ * useEffect(() => {
67
+ * stytch.magicLinks.authenticate('...')
68
+ * }, [stytch]);
69
+ */
38
70
  declare const useStytch: () => StytchClient;
39
71
  declare const withStytch: <T extends object>(Component: React.ComponentType<T & {
40
72
  stytch: StytchClient;
@@ -49,29 +81,124 @@ declare const withStytchSession: <T extends object>(Component: React.ComponentTy
49
81
  stytchSessionIsInitialized: boolean;
50
82
  stytchSessionIsFromCache: boolean;
51
83
  }>) => React.ComponentType<T>;
52
- type StytchProviderProps = {
84
+ interface StytchProviderProps {
85
+ /**
86
+ * A Stytch client instance, created using either {@link createStytchHeadlessClient} or {@link createStytchUIClient}
87
+ */
53
88
  stytch: StytchClient;
54
89
  children?: ReactNode;
55
- };
90
+ }
91
+ /**
92
+ * The Stytch Context Provider.
93
+ * Wrap your application with this component in `_app.js` in order to use Stytch everywhere in your app.
94
+ * @example
95
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
96
+ *
97
+ * return (
98
+ * <StytchProvider stytch={stytch}>
99
+ * <App />
100
+ * </StytchProvider>
101
+ * )
102
+ */
56
103
  declare const StytchProvider: ({ stytch, children }: StytchProviderProps) => JSX.Element;
104
+ interface StytchProps {
105
+ /**
106
+ * A {@link StytchLoginConfig} object. Add products and product-specific config to this object to change the login methods shown.
107
+ *
108
+ * @example
109
+ * {
110
+ * products: ['crypto', 'otps']
111
+ * }
112
+ *
113
+ * @example
114
+ * {
115
+ * products: ['emailMagicLinks'>]
116
+ * emailMagicLinksOptions: {
117
+ * loginRedirectURL: 'https://example.com/authenticate',
118
+ * signupRedirectURL: 'https://example.com/authenticate',
119
+ * }
120
+ * }
121
+ *
122
+ * @example
123
+ * {
124
+ * products: ['oauth'>]
125
+ * oauthOptions: {
126
+ * providers: [
127
+ * { type: 'google', one_tap: true, position: 'embedded' },
128
+ * { type: 'microsoft' },
129
+ * { type: 'apple' },
130
+ * { type: 'facebook' },
131
+ * ],
132
+ * }
133
+ * }
134
+ */
135
+ config: StytchLoginConfig;
136
+ /**
137
+ * An optional {@link StyleConfig} to customize the look and feel of the screen.
138
+ *
139
+ * @example
140
+ * {
141
+ * fontFamily: 'Arial, Helvetica, sans-serif',
142
+ * width: '360px',
143
+ * primaryColor: '#19303D',
144
+ * }
145
+ */
146
+ styles?: StyleConfig;
147
+ /**
148
+ * An optional {@link Callbacks} object.
149
+ *
150
+ * @example
151
+ * {
152
+ * onError: ({message}) => {
153
+ * console.error('Stytch login screen error', message)
154
+ * }
155
+ * }
156
+ *
157
+ * @example
158
+ * {
159
+ * onEvent: ({type, data}) => {
160
+ * if(type === StytchEventType.CryptoWalletAuthenticate) {
161
+ * console.log('Logged in with crypto wallet', data);
162
+ * }
163
+ * }
164
+ * }
165
+ */
166
+ callbacks?: Callbacks;
167
+ }
57
168
  /**
58
- * Stytch JS React Component
169
+ * The Stytch Login Screen component.
170
+ * This component can only be used with the Stytch UI Client - use {@link createStytchUIClient}
171
+ * in your `_app.jsx` file.
172
+ *
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
+ *
176
+ * @example
177
+ * <StytchLogin
178
+ * config={{
179
+ * products: ['emailMagicLinks', 'oauth'],
180
+ * emailMagicLinksOptions: {
181
+ * loginRedirectURL: 'https://example.com/authenticate',
182
+ * signupRedirectURL: 'https://example.com/authenticate',
183
+ * },
184
+ * oauthOptions: {
185
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
186
+ * },
187
+ * }}
188
+ * styles={{
189
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
190
+ * primaryColor: '#0577CA',
191
+ * width: '321px',
192
+ * }}
193
+ * callbacks={{
194
+ * onEvent: (event) => console.log(event)
195
+ * }}
196
+ * />
59
197
  *
60
- * [Documentation](https://stytch.com/docs/javascript-sdk)
198
+ * @param config - A {@link StytchLoginConfig} object
199
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
200
+ * @param callbacks - An optional {@link Callbacks} object
61
201
  */
62
- declare const Stytch: ({ config, styles, callbacks }: {
63
- config: Config;
64
- styles?: Partial<{
65
- fontFamily: string;
66
- width: string;
67
- primaryColor: string;
68
- primaryTextColor: string;
69
- secondaryTextColor: string;
70
- lightGrey: string;
71
- darkGrey: string;
72
- hideHeaderText: boolean;
73
- }> | undefined;
74
- callbacks?: Callbacks | undefined;
75
- }) => JSX.Element;
76
- export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, Stytch };
202
+ declare const StytchLogin: ({ config, styles, callbacks }: StytchProps) => JSX.Element;
203
+ export { StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser, StytchLogin };
77
204
  export type { StytchProviderProps };
package/dist/index.esm.js CHANGED
@@ -49,16 +49,55 @@ const StytchUserContext = createContext(initialUser);
49
49
  const StytchSessionContext = createContext(initialSession);
50
50
  const useIsMounted__INTERNAL = () => useContext(StytchContext).isMounted;
51
51
  const isUIClient = (client) => {
52
- return client.mount !== undefined;
52
+ return client.mountLogin !== undefined;
53
53
  };
54
+ /**
55
+ * Returns the active User.
56
+ * The Stytch SDKs are used for client-side authentication and session management.
57
+ * Check the isInitialized property to determine if the SDK has completed initialization.
58
+ * Check the fromCache property to determine if the session data is from persistent storage.
59
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
60
+ * @example
61
+ * const {user, isInitialized, fromCache} = useStytchUser();
62
+ * if (!isInitialized) {
63
+ * return <p>Loading...</p>;
64
+ * }
65
+ * return (<h1>Welcome, {user.name.first_name}</h1>);
66
+ */
54
67
  const useStytchUser = () => {
55
68
  invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));
56
69
  return useContext(StytchUserContext);
57
70
  };
71
+ /**
72
+ * Returns the user's active Stytch session.
73
+ * The Stytch SDKs are used for client-side authentication and session management.
74
+ * Check the isInitialized property to determine if the SDK has completed initialization.
75
+ * Check the fromCache property to determine if the session data is from persistent storage.
76
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
77
+ * @example
78
+ * const {session, isInitialized, fromCache} = useStytchSession();
79
+ * useEffect(() => {
80
+ * if (!isInitialized) {
81
+ * return;
82
+ * }
83
+ * if (!session) {
84
+ * router.replace('/login')
85
+ * }
86
+ * }, [session, isInitialized]);
87
+ */
58
88
  const useStytchSession = () => {
59
89
  invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));
60
90
  return useContext(StytchSessionContext);
61
91
  };
92
+ /**
93
+ * Returns the Stytch client stored in the Stytch context.
94
+ *
95
+ * @example
96
+ * const stytch = useStytch();
97
+ * useEffect(() => {
98
+ * stytch.magicLinks.authenticate('...')
99
+ * }, [stytch]);
100
+ */
62
101
  const useStytch = () => {
63
102
  const ctx = useContext(StytchContext);
64
103
  invariant(ctx.isMounted, noProviderError('useStytch'));
@@ -67,7 +106,7 @@ const useStytch = () => {
67
106
  const withStytch = (Component) => {
68
107
  const WithStytch = (props) => {
69
108
  invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));
70
- return React.createElement(Component, { ...props, stytch: useStytch() });
109
+ return React.createElement(Component, Object.assign({}, props, { stytch: useStytch() }));
71
110
  };
72
111
  WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;
73
112
  return WithStytch;
@@ -76,7 +115,7 @@ const withStytchUser = (Component) => {
76
115
  const WithStytchUser = (props) => {
77
116
  invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));
78
117
  const { user, isInitialized, fromCache } = useStytchUser();
79
- return (React.createElement(Component, { ...props, stytchUser: user, stytchUserIsInitialized: isInitialized, stytchUserIsFromCache: fromCache }));
118
+ return (React.createElement(Component, Object.assign({}, props, { stytchUser: user, stytchUserIsInitialized: isInitialized, stytchUserIsFromCache: fromCache })));
80
119
  };
81
120
  WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;
82
121
  return WithStytchUser;
@@ -85,13 +124,24 @@ const withStytchSession = (Component) => {
85
124
  const WithStytchSession = (props) => {
86
125
  invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));
87
126
  const { session, isInitialized, fromCache } = useStytchSession();
88
- return (React.createElement(Component, { ...props, stytchSession: session, stytchSessionIsInitialized: isInitialized, stytchSessionIsFromCache: fromCache }));
127
+ return (React.createElement(Component, Object.assign({}, props, { stytchSession: session, stytchSessionIsInitialized: isInitialized, stytchSessionIsFromCache: fromCache })));
89
128
  };
90
129
  WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;
91
130
  return WithStytchSession;
92
131
  };
132
+ /**
133
+ * The Stytch Context Provider.
134
+ * Wrap your application with this component in `_app.js` in order to use Stytch everywhere in your app.
135
+ * @example
136
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
137
+ *
138
+ * return (
139
+ * <StytchProvider stytch={stytch}>
140
+ * <App />
141
+ * </StytchProvider>
142
+ * )
143
+ */
93
144
  const StytchProvider = ({ stytch, children }) => {
94
- // invariant(!useIsMounted__INTERNAL(), providerMustBeUniqueError);
95
145
  const ctx = useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);
96
146
  const [user, setUser] = useAsyncState(initialUser);
97
147
  const [session, setSession] = useAsyncState(initialSession);
@@ -116,8 +166,8 @@ const StytchProvider = ({ stytch, children }) => {
116
166
  unsubscribeSession();
117
167
  };
118
168
  }, [stytch, setUser, setSession]);
119
- const finalSess = session.isInitialized === user.isInitialized ? session : initialSession;
120
- const finalUser = session.isInitialized === user.isInitialized ? user : initialUser;
169
+ const finalSess = !!session.session === !!user.user ? session : initialSession;
170
+ const finalUser = !!session.session === !!user.user ? user : initialUser;
121
171
  return (React.createElement(StytchContext.Provider, { value: ctx },
122
172
  React.createElement(StytchUserContext.Provider, { value: finalUser },
123
173
  React.createElement(StytchSessionContext.Provider, { value: finalSess }, children))));
@@ -127,12 +177,41 @@ const StytchProvider = ({ stytch, children }) => {
127
177
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
128
178
 
129
179
  /**
130
- * Stytch JS React Component
180
+ * The Stytch Login Screen component.
181
+ * This component can only be used with the Stytch UI Client - use {@link createStytchUIClient}
182
+ * in your `_app.jsx` file.
131
183
  *
132
- * [Documentation](https://stytch.com/docs/javascript-sdk)
184
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
185
+ * and {@link https://storybook.stytch.com interactive examples} for more.
186
+ *
187
+ * @example
188
+ * <StytchLogin
189
+ * config={{
190
+ * products: ['emailMagicLinks', 'oauth'],
191
+ * emailMagicLinksOptions: {
192
+ * loginRedirectURL: 'https://example.com/authenticate',
193
+ * signupRedirectURL: 'https://example.com/authenticate',
194
+ * },
195
+ * oauthOptions: {
196
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
197
+ * },
198
+ * }}
199
+ * styles={{
200
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
201
+ * primaryColor: '#0577CA',
202
+ * width: '321px',
203
+ * }}
204
+ * callbacks={{
205
+ * onEvent: (event) => console.log(event)
206
+ * }}
207
+ * />
208
+ *
209
+ * @param config - A {@link StytchLoginConfig} object
210
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
211
+ * @param callbacks - An optional {@link Callbacks} object
133
212
  */
134
- const Stytch = ({ config, styles, callbacks, }) => {
135
- invariant(useIsMounted__INTERNAL(), noProviderError('<Stytch />'));
213
+ const StytchLogin = ({ config, styles, callbacks }) => {
214
+ invariant(useIsMounted__INTERNAL(), noProviderError('<StytchLogin />'));
136
215
  const stytchClient = useStytch();
137
216
  const containerEl = useRef(null);
138
217
  useIsomorphicLayoutEffect(() => {
@@ -142,20 +221,18 @@ const Stytch = ({ config, styles, callbacks, }) => {
142
221
  if (!containerEl.current) {
143
222
  return;
144
223
  }
145
- if (containerEl.current.id) {
146
- return;
224
+ if (!containerEl.current.id) {
225
+ const randId = Math.floor(Math.random() * 1e6);
226
+ containerEl.current.id = `stytch-magic-link-${randId}`;
147
227
  }
148
- const randId = Math.floor(Math.random() * 1e6);
149
- const elementId = `stytch-magic-link-${randId}`;
150
- containerEl.current.id = elementId;
151
- stytchClient.mount({
228
+ stytchClient.mountLogin({
152
229
  config,
153
230
  callbacks,
154
- elementId: `#${elementId}`,
231
+ elementId: `#${containerEl.current.id}`,
155
232
  styles,
156
233
  });
157
- }, [stytchClient]);
234
+ }, [stytchClient, config, styles, callbacks]);
158
235
  return React.createElement("div", { ref: containerEl });
159
236
  };
160
237
 
161
- export { Stytch, StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser };
238
+ export { StytchLogin, StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser };
@@ -1,3 +1,16 @@
1
1
  import { StytchHeadlessClient } from "@stytch/vanilla-js/headless";
2
+ /**
3
+ * Creates a Headless Stytch client object to call the stytch APIs.
4
+ * The Stytch client is not available serverside.
5
+ * @example
6
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
7
+ *
8
+ * return (
9
+ * <StytchProvider stytch={stytch}>
10
+ * <App />
11
+ * </StytchProvider>
12
+ * )
13
+ * @returns A {@link StytchHeadlessClient}
14
+ */
2
15
  declare const createStytchHeadlessClient: (_PUBLIC_TOKEN: string) => StytchHeadlessClient;
3
16
  export { createStytchHeadlessClient };
@@ -1,3 +1,16 @@
1
1
  import { StytchHeadlessClient } from "@stytch/vanilla-js/headless";
2
+ /**
3
+ * Creates a Headless Stytch client object to call the stytch APIs.
4
+ * The Stytch client is not available serverside.
5
+ * @example
6
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
7
+ *
8
+ * return (
9
+ * <StytchProvider stytch={stytch}>
10
+ * <App />
11
+ * </StytchProvider>
12
+ * )
13
+ * @returns A {@link StytchHeadlessClient}
14
+ */
2
15
  declare const createStytchHeadlessClient: (_PUBLIC_TOKEN: string) => StytchHeadlessClient;
3
16
  export { createStytchHeadlessClient };
@@ -38,6 +38,19 @@ const createProxy = (path) => {
38
38
  };
39
39
  const createStytchSSRProxy = () => createProxy('stytch');
40
40
 
41
+ /**
42
+ * Creates a Headless Stytch client object to call the stytch APIs.
43
+ * The Stytch client is not available serverside.
44
+ * @example
45
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
46
+ *
47
+ * return (
48
+ * <StytchProvider stytch={stytch}>
49
+ * <App />
50
+ * </StytchProvider>
51
+ * )
52
+ * @returns A {@link StytchHeadlessClient}
53
+ */
41
54
  const createStytchHeadlessClient = (...args) => {
42
55
  if (typeof window === 'undefined') {
43
56
  return createStytchSSRProxy();
@@ -42,6 +42,19 @@ const createProxy = (path) => {
42
42
  };
43
43
  const createStytchSSRProxy = () => createProxy('stytch');
44
44
 
45
+ /**
46
+ * Creates a Headless Stytch client object to call the stytch APIs.
47
+ * The Stytch client is not available serverside.
48
+ * @example
49
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
50
+ *
51
+ * return (
52
+ * <StytchProvider stytch={stytch}>
53
+ * <App />
54
+ * </StytchProvider>
55
+ * )
56
+ * @returns A {@link StytchHeadlessClient}
57
+ */
45
58
  const createStytchHeadlessClient = (...args) => {
46
59
  if (typeof window === 'undefined') {
47
60
  return createStytchSSRProxy();
package/dist/index.js CHANGED
@@ -57,16 +57,55 @@ const StytchUserContext = React.createContext(initialUser);
57
57
  const StytchSessionContext = React.createContext(initialSession);
58
58
  const useIsMounted__INTERNAL = () => React.useContext(StytchContext).isMounted;
59
59
  const isUIClient = (client) => {
60
- return client.mount !== undefined;
60
+ return client.mountLogin !== undefined;
61
61
  };
62
+ /**
63
+ * Returns the active User.
64
+ * The Stytch SDKs are used for client-side authentication and session management.
65
+ * Check the isInitialized property to determine if the SDK has completed initialization.
66
+ * Check the fromCache property to determine if the session data is from persistent storage.
67
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
68
+ * @example
69
+ * const {user, isInitialized, fromCache} = useStytchUser();
70
+ * if (!isInitialized) {
71
+ * return <p>Loading...</p>;
72
+ * }
73
+ * return (<h1>Welcome, {user.name.first_name}</h1>);
74
+ */
62
75
  const useStytchUser = () => {
63
76
  invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));
64
77
  return React.useContext(StytchUserContext);
65
78
  };
79
+ /**
80
+ * Returns the user's active Stytch session.
81
+ * The Stytch SDKs are used for client-side authentication and session management.
82
+ * Check the isInitialized property to determine if the SDK has completed initialization.
83
+ * Check the fromCache property to determine if the session data is from persistent storage.
84
+ * See Next's {@link https://nextjs.org/docs/authentication#authenticating-statically-generated-pages documentation} for more.
85
+ * @example
86
+ * const {session, isInitialized, fromCache} = useStytchSession();
87
+ * useEffect(() => {
88
+ * if (!isInitialized) {
89
+ * return;
90
+ * }
91
+ * if (!session) {
92
+ * router.replace('/login')
93
+ * }
94
+ * }, [session, isInitialized]);
95
+ */
66
96
  const useStytchSession = () => {
67
97
  invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));
68
98
  return React.useContext(StytchSessionContext);
69
99
  };
100
+ /**
101
+ * Returns the Stytch client stored in the Stytch context.
102
+ *
103
+ * @example
104
+ * const stytch = useStytch();
105
+ * useEffect(() => {
106
+ * stytch.magicLinks.authenticate('...')
107
+ * }, [stytch]);
108
+ */
70
109
  const useStytch = () => {
71
110
  const ctx = React.useContext(StytchContext);
72
111
  invariant(ctx.isMounted, noProviderError('useStytch'));
@@ -75,7 +114,7 @@ const useStytch = () => {
75
114
  const withStytch = (Component) => {
76
115
  const WithStytch = (props) => {
77
116
  invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));
78
- return React__default["default"].createElement(Component, { ...props, stytch: useStytch() });
117
+ return React__default["default"].createElement(Component, Object.assign({}, props, { stytch: useStytch() }));
79
118
  };
80
119
  WithStytch.displayName = `withStytch(${Component.displayName || Component.name || 'Component'})`;
81
120
  return WithStytch;
@@ -84,7 +123,7 @@ const withStytchUser = (Component) => {
84
123
  const WithStytchUser = (props) => {
85
124
  invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));
86
125
  const { user, isInitialized, fromCache } = useStytchUser();
87
- return (React__default["default"].createElement(Component, { ...props, stytchUser: user, stytchUserIsInitialized: isInitialized, stytchUserIsFromCache: fromCache }));
126
+ return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchUser: user, stytchUserIsInitialized: isInitialized, stytchUserIsFromCache: fromCache })));
88
127
  };
89
128
  WithStytchUser.displayName = `withStytchUser(${Component.displayName || Component.name || 'Component'})`;
90
129
  return WithStytchUser;
@@ -93,13 +132,24 @@ const withStytchSession = (Component) => {
93
132
  const WithStytchSession = (props) => {
94
133
  invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));
95
134
  const { session, isInitialized, fromCache } = useStytchSession();
96
- return (React__default["default"].createElement(Component, { ...props, stytchSession: session, stytchSessionIsInitialized: isInitialized, stytchSessionIsFromCache: fromCache }));
135
+ return (React__default["default"].createElement(Component, Object.assign({}, props, { stytchSession: session, stytchSessionIsInitialized: isInitialized, stytchSessionIsFromCache: fromCache })));
97
136
  };
98
137
  WithStytchSession.displayName = `withStytchSession(${Component.displayName || Component.name || 'Component'})`;
99
138
  return WithStytchSession;
100
139
  };
140
+ /**
141
+ * The Stytch Context Provider.
142
+ * Wrap your application with this component in `_app.js` in order to use Stytch everywhere in your app.
143
+ * @example
144
+ * const stytch = createStytchHeadlessClient('public-token-<find yours in the stytch dashboard>')
145
+ *
146
+ * return (
147
+ * <StytchProvider stytch={stytch}>
148
+ * <App />
149
+ * </StytchProvider>
150
+ * )
151
+ */
101
152
  const StytchProvider = ({ stytch, children }) => {
102
- // invariant(!useIsMounted__INTERNAL(), providerMustBeUniqueError);
103
153
  const ctx = React.useMemo(() => ({ client: stytch, isMounted: true }), [stytch]);
104
154
  const [user, setUser] = useAsyncState(initialUser);
105
155
  const [session, setSession] = useAsyncState(initialSession);
@@ -124,8 +174,8 @@ const StytchProvider = ({ stytch, children }) => {
124
174
  unsubscribeSession();
125
175
  };
126
176
  }, [stytch, setUser, setSession]);
127
- const finalSess = session.isInitialized === user.isInitialized ? session : initialSession;
128
- const finalUser = session.isInitialized === user.isInitialized ? user : initialUser;
177
+ const finalSess = !!session.session === !!user.user ? session : initialSession;
178
+ const finalUser = !!session.session === !!user.user ? user : initialUser;
129
179
  return (React__default["default"].createElement(StytchContext.Provider, { value: ctx },
130
180
  React__default["default"].createElement(StytchUserContext.Provider, { value: finalUser },
131
181
  React__default["default"].createElement(StytchSessionContext.Provider, { value: finalSess }, children))));
@@ -135,12 +185,41 @@ const StytchProvider = ({ stytch, children }) => {
135
185
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
136
186
 
137
187
  /**
138
- * Stytch JS React Component
188
+ * The Stytch Login Screen component.
189
+ * This component can only be used with the Stytch UI Client - use {@link createStytchUIClient}
190
+ * in your `_app.jsx` file.
139
191
  *
140
- * [Documentation](https://stytch.com/docs/javascript-sdk)
192
+ * See the {@link https://stytch.com/docs/sdks/javascript-sdk online reference}
193
+ * and {@link https://storybook.stytch.com interactive examples} for more.
194
+ *
195
+ * @example
196
+ * <StytchLogin
197
+ * config={{
198
+ * products: ['emailMagicLinks', 'oauth'],
199
+ * emailMagicLinksOptions: {
200
+ * loginRedirectURL: 'https://example.com/authenticate',
201
+ * signupRedirectURL: 'https://example.com/authenticate',
202
+ * },
203
+ * oauthOptions: {
204
+ * providers: [{ type: OAuthProviders.Google }, { type: OAuthProviders.Microsoft }],
205
+ * },
206
+ * }}
207
+ * styles={{
208
+ * fontFamily: '"Helvetica New", Helvetica, sans-serif',
209
+ * primaryColor: '#0577CA',
210
+ * width: '321px',
211
+ * }}
212
+ * callbacks={{
213
+ * onEvent: (event) => console.log(event)
214
+ * }}
215
+ * />
216
+ *
217
+ * @param config - A {@link StytchLoginConfig} object
218
+ * @param styles - An optional {@link StyleConfig} to customize the look and feel of the screen.
219
+ * @param callbacks - An optional {@link Callbacks} object
141
220
  */
142
- const Stytch = ({ config, styles, callbacks, }) => {
143
- invariant(useIsMounted__INTERNAL(), noProviderError('<Stytch />'));
221
+ const StytchLogin = ({ config, styles, callbacks }) => {
222
+ invariant(useIsMounted__INTERNAL(), noProviderError('<StytchLogin />'));
144
223
  const stytchClient = useStytch();
145
224
  const containerEl = React.useRef(null);
146
225
  useIsomorphicLayoutEffect(() => {
@@ -150,23 +229,21 @@ const Stytch = ({ config, styles, callbacks, }) => {
150
229
  if (!containerEl.current) {
151
230
  return;
152
231
  }
153
- if (containerEl.current.id) {
154
- return;
232
+ if (!containerEl.current.id) {
233
+ const randId = Math.floor(Math.random() * 1e6);
234
+ containerEl.current.id = `stytch-magic-link-${randId}`;
155
235
  }
156
- const randId = Math.floor(Math.random() * 1e6);
157
- const elementId = `stytch-magic-link-${randId}`;
158
- containerEl.current.id = elementId;
159
- stytchClient.mount({
236
+ stytchClient.mountLogin({
160
237
  config,
161
238
  callbacks,
162
- elementId: `#${elementId}`,
239
+ elementId: `#${containerEl.current.id}`,
163
240
  styles,
164
241
  });
165
- }, [stytchClient]);
242
+ }, [stytchClient, config, styles, callbacks]);
166
243
  return React__default["default"].createElement("div", { ref: containerEl });
167
244
  };
168
245
 
169
- exports.Stytch = Stytch;
246
+ exports.StytchLogin = StytchLogin;
170
247
  exports.StytchProvider = StytchProvider;
171
248
  exports.useStytch = useStytch;
172
249
  exports.useStytchSession = useStytchSession;
@@ -1,3 +1,17 @@
1
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
+ */
2
16
  declare const createStytchUIClient: (_PUBLIC_TOKEN: string) => StytchUIClient;
3
17
  export { createStytchUIClient };
@@ -1,3 +1,17 @@
1
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
+ */
2
16
  declare const createStytchUIClient: (_PUBLIC_TOKEN: string) => StytchUIClient;
3
17
  export { createStytchUIClient };
@@ -38,6 +38,20 @@ const createProxy = (path) => {
38
38
  };
39
39
  const createStytchSSRProxy = () => createProxy('stytch');
40
40
 
41
+ /**
42
+ * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.
43
+ * The Stytch client is not available serverside.
44
+ * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.
45
+ * @example
46
+ * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')
47
+ *
48
+ * return (
49
+ * <StytchProvider stytch={stytch}>
50
+ * <App />
51
+ * </StytchProvider>
52
+ * )
53
+ * @returns A {@link StytchUIClient}
54
+ */
41
55
  const createStytchUIClient = (...args) => {
42
56
  if (typeof window === 'undefined') {
43
57
  return createStytchSSRProxy();
package/dist/index.ui.js CHANGED
@@ -42,6 +42,20 @@ const createProxy = (path) => {
42
42
  };
43
43
  const createStytchSSRProxy = () => createProxy('stytch');
44
44
 
45
+ /**
46
+ * Creates a Stytch UI client object to call the Stytch APIs and render Stytch UI components.
47
+ * The Stytch client is not available serverside.
48
+ * If you do not use Stytch UI components, use {@link createStytchHeadlessClient} to reduce your bundle size.
49
+ * @example
50
+ * const stytch = createStytchUIClient('public-token-<find yours in the stytch dashboard>')
51
+ *
52
+ * return (
53
+ * <StytchProvider stytch={stytch}>
54
+ * <App />
55
+ * </StytchProvider>
56
+ * )
57
+ * @returns A {@link StytchUIClient}
58
+ */
45
59
  const createStytchUIClient = (...args) => {
46
60
  if (typeof window === 'undefined') {
47
61
  return createStytchSSRProxy();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stytch/nextjs",
3
- "version": "0.0.2-0",
3
+ "version": "0.3.0",
4
4
  "description": "Stytch's official Next.js Library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -21,15 +21,26 @@
21
21
  "author": "Stytch",
22
22
  "devDependencies": {
23
23
  "@babel/runtime": "^7.18.6",
24
- "@stytch/vanilla-js": "0.0.2-0",
24
+ "@stytch/vanilla-js": "0.2.0",
25
25
  "eslint-config-custom": "0.0.0",
26
26
  "rollup": "^2.56.3",
27
- "typescript": "^4.5.3"
27
+ "typescript": "4.7.4"
28
28
  },
29
29
  "peerDependencies": {
30
- "@stytch/vanilla-js": "^0.0.2-0",
30
+ "@stytch/vanilla-js": "^0.2.0",
31
31
  "react": ">= 17.0.2",
32
32
  "react-dom": ">= 17.0.2"
33
33
  },
34
- "stableVersion": "0.0.1"
35
- }
34
+ "homepage": "https://stytch.com/docs/sdks/javascript-sdk",
35
+ "keywords": [
36
+ "stytch",
37
+ "react",
38
+ "nextjs",
39
+ "typescript",
40
+ "auth",
41
+ "authentication",
42
+ "session",
43
+ "jwt",
44
+ "user"
45
+ ]
46
+ }