@stytch/react 0.0.0-next-20240815193523
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 +348 -0
- package/LICENSE +17 -0
- package/README.md +157 -0
- package/b2b/adminPortal/package.json +6 -0
- package/b2b/package.json +6 -0
- package/dist/StytchB2BContext-8acafb28.d.ts +165 -0
- package/dist/StytchB2BContext-8acafb28.js +217 -0
- package/dist/StytchB2BContext-ce9e254c.d.ts +165 -0
- package/dist/StytchB2BContext-ce9e254c.js +235 -0
- package/dist/adminPortal/index.d.ts +35 -0
- package/dist/adminPortal/index.esm.d.ts +35 -0
- package/dist/adminPortal/index.esm.js +47 -0
- package/dist/adminPortal/index.js +62 -0
- package/dist/b2b/index.d.ts +108 -0
- package/dist/b2b/index.esm.d.ts +108 -0
- package/dist/b2b/index.esm.js +66 -0
- package/dist/b2b/index.js +84 -0
- package/dist/createDeepEqual-5555f2e1.d.ts +5 -0
- package/dist/index-b14d4efe.d.ts +2 -0
- package/dist/index.d.ts +234 -0
- package/dist/index.esm.d.ts +234 -0
- package/dist/index.esm.js +297 -0
- package/dist/index.js +314 -0
- package/dist/invariant-568a7633.d.ts +27 -0
- package/dist/invariant-568a7633.js +88 -0
- package/dist/invariant-ae5a5bce.d.ts +27 -0
- package/dist/invariant-ae5a5bce.js +97 -0
- package/package.json +52 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
# @stytch/react
|
|
2
|
+
|
|
3
|
+
## 0.0.0-next-20240815193523
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [c23db6cd]
|
|
8
|
+
- @stytch/vanilla-js@0.0.0-next-20240815193523
|
|
9
|
+
|
|
10
|
+
## 18.3.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 6d06cce0: Load Admin Portal components from vanilla-js directly
|
|
15
|
+
|
|
16
|
+
## 18.3.2
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 7d2c2878: Fix admin portal component props
|
|
21
|
+
|
|
22
|
+
## 18.3.1
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- 089c986a: Guard references to localStorage and sessionStorage
|
|
27
|
+
|
|
28
|
+
## 18.3.0
|
|
29
|
+
|
|
30
|
+
### Minor Changes
|
|
31
|
+
|
|
32
|
+
- 3183b459: Add `AdminPortalMemberManagement` component to `@stytch/react/b2b/adminPortal`
|
|
33
|
+
|
|
34
|
+
## 18.2.0
|
|
35
|
+
|
|
36
|
+
### Minor Changes
|
|
37
|
+
|
|
38
|
+
- 1ade8d93: Add `AdminPortalOrgSettings` component to `@stytch/react/b2b/adminPortal`
|
|
39
|
+
|
|
40
|
+
## 18.1.0
|
|
41
|
+
|
|
42
|
+
### Minor Changes
|
|
43
|
+
|
|
44
|
+
- a99f21b8: Add `AdminPortalSSO` component to `@stytch/react/b2b/adminPortal`
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- Updated dependencies [0f448e7e]
|
|
49
|
+
- Updated dependencies [a99f21b8]
|
|
50
|
+
- @stytch/vanilla-js@4.13.0
|
|
51
|
+
|
|
52
|
+
## 18.0.0
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- Updated dependencies [cbab0c30]
|
|
57
|
+
- @stytch/vanilla-js@4.12.0
|
|
58
|
+
|
|
59
|
+
## 17.0.0
|
|
60
|
+
|
|
61
|
+
### Major Changes
|
|
62
|
+
|
|
63
|
+
- a0fbe9f: Update minimum peer dependency on `@stytch/vanilla-js` to `^4.9.0`
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- Updated dependencies [a0fbe9f]
|
|
68
|
+
- Updated dependencies [a0fbe9f]
|
|
69
|
+
- @stytch/vanilla-js@4.9.0
|
|
70
|
+
|
|
71
|
+
## 16.0.0
|
|
72
|
+
|
|
73
|
+
### Patch Changes
|
|
74
|
+
|
|
75
|
+
- Updated dependencies [f604dcb]
|
|
76
|
+
- @stytch/vanilla-js@4.7.0
|
|
77
|
+
|
|
78
|
+
## 15.0.0
|
|
79
|
+
|
|
80
|
+
### Minor Changes
|
|
81
|
+
|
|
82
|
+
- 223e30e: Add `useStytchOrganization` hook for B2B
|
|
83
|
+
|
|
84
|
+
### Patch Changes
|
|
85
|
+
|
|
86
|
+
- Updated dependencies [223e30e]
|
|
87
|
+
- @stytch/vanilla-js@4.2.0
|
|
88
|
+
|
|
89
|
+
## 14.0.1
|
|
90
|
+
|
|
91
|
+
### Patch Changes
|
|
92
|
+
|
|
93
|
+
- e6832cb: Fix an issue where `fromCache` would not update to `false` after cached data was refreshed
|
|
94
|
+
- Updated dependencies [e6832cb]
|
|
95
|
+
- @stytch/vanilla-js@4.1.1
|
|
96
|
+
|
|
97
|
+
## 14.0.0
|
|
98
|
+
|
|
99
|
+
### Patch Changes
|
|
100
|
+
|
|
101
|
+
- Updated dependencies [2379b29]
|
|
102
|
+
- @stytch/vanilla-js@4.1.0
|
|
103
|
+
|
|
104
|
+
## 13.0.0
|
|
105
|
+
|
|
106
|
+
### Minor Changes
|
|
107
|
+
|
|
108
|
+
- 6890694: Mark stytch.member as deprecated in favor of stytch.self
|
|
109
|
+
Adds RBAC functionality
|
|
110
|
+
|
|
111
|
+
### Patch Changes
|
|
112
|
+
|
|
113
|
+
- Updated dependencies [9ee61b3]
|
|
114
|
+
- Updated dependencies [b34293a]
|
|
115
|
+
- Updated dependencies [c3c108b]
|
|
116
|
+
- Updated dependencies [6890694]
|
|
117
|
+
- @stytch/vanilla-js@4.0.0
|
|
118
|
+
|
|
119
|
+
## 12.0.0
|
|
120
|
+
|
|
121
|
+
### Patch Changes
|
|
122
|
+
|
|
123
|
+
- Updated dependencies [ec1962c]
|
|
124
|
+
- @stytch/vanilla-js@3.2.0
|
|
125
|
+
|
|
126
|
+
## 11.0.0
|
|
127
|
+
|
|
128
|
+
### Minor Changes
|
|
129
|
+
|
|
130
|
+
- 8cff174: B2C Passkeys Headless Support & UI components
|
|
131
|
+
|
|
132
|
+
### Patch Changes
|
|
133
|
+
|
|
134
|
+
- Updated dependencies [8cff174]
|
|
135
|
+
- @stytch/vanilla-js@3.1.0
|
|
136
|
+
|
|
137
|
+
## 10.0.0
|
|
138
|
+
|
|
139
|
+
### Patch Changes
|
|
140
|
+
|
|
141
|
+
- Updated dependencies [5dd9d24]
|
|
142
|
+
- @stytch/vanilla-js@3.0.0
|
|
143
|
+
|
|
144
|
+
## 9.0.0
|
|
145
|
+
|
|
146
|
+
### Patch Changes
|
|
147
|
+
|
|
148
|
+
- 47eb388: Add Device Fingerprinting to the React Native SDK
|
|
149
|
+
- Updated dependencies [47eb388]
|
|
150
|
+
- Updated dependencies [d008ef5]
|
|
151
|
+
- Updated dependencies [47eb388]
|
|
152
|
+
- Updated dependencies [7c1940e]
|
|
153
|
+
- @stytch/vanilla-js@2.2.0
|
|
154
|
+
|
|
155
|
+
## 8.0.0
|
|
156
|
+
|
|
157
|
+
### Patch Changes
|
|
158
|
+
|
|
159
|
+
- Updated dependencies [67d42f0]
|
|
160
|
+
- @stytch/vanilla-js@2.1.0
|
|
161
|
+
|
|
162
|
+
## 7.0.2
|
|
163
|
+
|
|
164
|
+
### Patch Changes
|
|
165
|
+
|
|
166
|
+
- 1b1ea1b: updateStateAndTokens call in resetBySession and resetExistingPassword
|
|
167
|
+
- Updated dependencies [1b1ea1b]
|
|
168
|
+
- Updated dependencies [47cd46c]
|
|
169
|
+
- @stytch/vanilla-js@2.0.3
|
|
170
|
+
|
|
171
|
+
## 7.0.1
|
|
172
|
+
|
|
173
|
+
### Patch Changes
|
|
174
|
+
|
|
175
|
+
- 0a18c34: Add docs for new verified fields on Member objects, and fix some docs links
|
|
176
|
+
- Updated dependencies [9fd5d96]
|
|
177
|
+
- Updated dependencies [0a18c34]
|
|
178
|
+
- @stytch/vanilla-js@2.0.1
|
|
179
|
+
|
|
180
|
+
## 7.0.0
|
|
181
|
+
|
|
182
|
+
### Major Changes
|
|
183
|
+
|
|
184
|
+
- a4083c7: Breaking Changes: The intermediate session token (IST) will no longer be accepted as an argument for the discovery list organizations, intermediate sessions exchange, and create organization via discovery endpoints. The IST will be passed in automatically. ISTs are stored as browser cookies or persisted on device when they are generated after calls to discovery authenticate endpoints, such as email magic link discovery authenticate, or primary authenticate endpoints in the case where MFA is required, such as email magic link authenticate or SSO authenticate.
|
|
185
|
+
|
|
186
|
+
New Features: Our B2B product now supports multi-factor authentication (MFA) with one-time passcodes (OTPs) via SMS. MFA policies can be set on the Organization level or on the Member level. See the Stytch docs for more information.
|
|
187
|
+
|
|
188
|
+
### Patch Changes
|
|
189
|
+
|
|
190
|
+
- Updated dependencies [a4083c7]
|
|
191
|
+
- @stytch/vanilla-js@2.0.0
|
|
192
|
+
|
|
193
|
+
## 6.0.0
|
|
194
|
+
|
|
195
|
+
### Patch Changes
|
|
196
|
+
|
|
197
|
+
- Updated dependencies [e7302d7]
|
|
198
|
+
- @stytch/vanilla-js@1.1.0
|
|
199
|
+
|
|
200
|
+
## 5.0.0
|
|
201
|
+
|
|
202
|
+
### Patch Changes
|
|
203
|
+
|
|
204
|
+
- Updated dependencies [f9c36c9]
|
|
205
|
+
- @stytch/vanilla-js@1.0.0
|
|
206
|
+
|
|
207
|
+
## 4.0.0
|
|
208
|
+
|
|
209
|
+
### Minor Changes
|
|
210
|
+
|
|
211
|
+
- c8e2d0b: B2B Passwords UI components
|
|
212
|
+
|
|
213
|
+
### Patch Changes
|
|
214
|
+
|
|
215
|
+
- Updated dependencies [c8e2d0b]
|
|
216
|
+
- @stytch/vanilla-js@0.14.0
|
|
217
|
+
|
|
218
|
+
## 3.0.0
|
|
219
|
+
|
|
220
|
+
### Minor Changes
|
|
221
|
+
|
|
222
|
+
- 15dbe7d: Releasing UI components for our B2B SDKs.
|
|
223
|
+
|
|
224
|
+
### Patch Changes
|
|
225
|
+
|
|
226
|
+
- Updated dependencies [15dbe7d]
|
|
227
|
+
- @stytch/vanilla-js@0.13.0
|
|
228
|
+
|
|
229
|
+
## 2.0.0
|
|
230
|
+
|
|
231
|
+
### Patch Changes
|
|
232
|
+
|
|
233
|
+
- 6a27584: Make organization name and slug optional for discovery organization create
|
|
234
|
+
- Updated dependencies [dde1f2a]
|
|
235
|
+
- Updated dependencies [6a27584]
|
|
236
|
+
- @stytch/vanilla-js@0.12.0
|
|
237
|
+
|
|
238
|
+
## 1.0.2
|
|
239
|
+
|
|
240
|
+
### Patch Changes
|
|
241
|
+
|
|
242
|
+
- 79ca7ba: Add locale argument to B2B email magic link methods
|
|
243
|
+
- Updated dependencies [79ca7ba]
|
|
244
|
+
- @stytch/vanilla-js@0.11.3
|
|
245
|
+
|
|
246
|
+
## 1.0.1
|
|
247
|
+
|
|
248
|
+
### Patch Changes
|
|
249
|
+
|
|
250
|
+
- c924765: Include the b2b directory in package.json for the B2B SDK entrypoint
|
|
251
|
+
- Updated dependencies [c924765]
|
|
252
|
+
- @stytch/vanilla-js@0.11.2
|
|
253
|
+
|
|
254
|
+
## 1.0.0
|
|
255
|
+
|
|
256
|
+
### Minor Changes
|
|
257
|
+
|
|
258
|
+
- c0e42bc: Add B2B Discovery headless client and session exchange method
|
|
259
|
+
|
|
260
|
+
### Patch Changes
|
|
261
|
+
|
|
262
|
+
- Updated dependencies [c0e42bc]
|
|
263
|
+
- @stytch/vanilla-js@0.11.0
|
|
264
|
+
|
|
265
|
+
## 0.10.3
|
|
266
|
+
|
|
267
|
+
### Patch Changes
|
|
268
|
+
|
|
269
|
+
- 1652706: Fix session/user persisting after logging out
|
|
270
|
+
- Updated dependencies [1652706]
|
|
271
|
+
- @stytch/vanilla-js@0.10.7
|
|
272
|
+
|
|
273
|
+
## 0.10.2
|
|
274
|
+
|
|
275
|
+
### Patch Changes
|
|
276
|
+
|
|
277
|
+
- ca5a31d: SDK-877 Fix session/user persisting after logging out
|
|
278
|
+
- Updated dependencies [ca5a31d]
|
|
279
|
+
- @stytch/vanilla-js@0.10.6
|
|
280
|
+
|
|
281
|
+
## 0.10.1
|
|
282
|
+
|
|
283
|
+
### Patch Changes
|
|
284
|
+
|
|
285
|
+
- f1810c4: Add React Native OAuth callback, PKCE fix
|
|
286
|
+
- Updated dependencies [f1810c4]
|
|
287
|
+
- @stytch/vanilla-js@0.10.2
|
|
288
|
+
|
|
289
|
+
## 0.10.0
|
|
290
|
+
|
|
291
|
+
### Minor Changes
|
|
292
|
+
|
|
293
|
+
- Launching B2B SDKs
|
|
294
|
+
|
|
295
|
+
### Patch Changes
|
|
296
|
+
|
|
297
|
+
- Updated dependencies
|
|
298
|
+
- @stytch/vanilla-js@0.10.0
|
|
299
|
+
|
|
300
|
+
## 0.9.0
|
|
301
|
+
|
|
302
|
+
### Patch Changes
|
|
303
|
+
|
|
304
|
+
- Updated dependencies
|
|
305
|
+
- @stytch/vanilla-js@0.9.0
|
|
306
|
+
|
|
307
|
+
## 0.6.0
|
|
308
|
+
|
|
309
|
+
### Minor Changes
|
|
310
|
+
|
|
311
|
+
- Add support for template ID parameters to Magic link Login or create and Send methods, Email OTP Login or create and Send methods, and Reset Password Start
|
|
312
|
+
|
|
313
|
+
### Patch Changes
|
|
314
|
+
|
|
315
|
+
- Updated dependencies
|
|
316
|
+
- Updated dependencies [ac0cf89]
|
|
317
|
+
- @stytch/vanilla-js@0.6.0
|
|
318
|
+
|
|
319
|
+
## 0.5.0
|
|
320
|
+
|
|
321
|
+
### Patch Changes
|
|
322
|
+
|
|
323
|
+
- 422c698: Add type definitions for User Metadata fields
|
|
324
|
+
- Updated dependencies [422c698]
|
|
325
|
+
- Updated dependencies
|
|
326
|
+
- @stytch/vanilla-js@0.5.0
|
|
327
|
+
|
|
328
|
+
## 0.4.6
|
|
329
|
+
|
|
330
|
+
### Patch Changes
|
|
331
|
+
|
|
332
|
+
- Add support for custom email domains in magic link confirmation screen
|
|
333
|
+
- Updated dependencies
|
|
334
|
+
- @stytch/vanilla-js@0.4.6
|
|
335
|
+
|
|
336
|
+
## 0.4.5
|
|
337
|
+
|
|
338
|
+
### Patch Changes
|
|
339
|
+
|
|
340
|
+
- Reset Password component doc fixes
|
|
341
|
+
|
|
342
|
+
## 0.4.4
|
|
343
|
+
|
|
344
|
+
### Patch Changes
|
|
345
|
+
|
|
346
|
+
- Send methods in the SDK
|
|
347
|
+
- Updated dependencies
|
|
348
|
+
- @stytch/vanilla-js@0.4.4
|
package/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2021 stytchauth
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all
|
|
10
|
+
copies or substantial portions of the Software.
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
12
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
14
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
17
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# @stytch/react
|
|
2
|
+
|
|
3
|
+
Stytch's React Library
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
With `npm`
|
|
8
|
+
`npm install @stytch/react @stytch/vanilla-js --save`
|
|
9
|
+
|
|
10
|
+
## Documentation
|
|
11
|
+
|
|
12
|
+
For full documentation please refer to Stytch's javascript SDK documentation at https://stytch.com/docs/sdks/javascript-sdk.
|
|
13
|
+
|
|
14
|
+
## Example Usage
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
import { StytchProvider } from '@stytch/react';
|
|
18
|
+
import { StytchUIClient } from '@stytch/vanilla-js';
|
|
19
|
+
|
|
20
|
+
const stytch = new StytchUIClient('public-token-<find yours in the stytch dashboard>');
|
|
21
|
+
|
|
22
|
+
// Wrap your App in the StytchProvider
|
|
23
|
+
ReactDOM.render(
|
|
24
|
+
<StytchProvider stytch={stytch}>
|
|
25
|
+
<App />
|
|
26
|
+
</StytchProvider>,
|
|
27
|
+
document.getElementById('root'),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// Now use Stytch in your components
|
|
31
|
+
const App = () => {
|
|
32
|
+
const stytchProps = {
|
|
33
|
+
config: {
|
|
34
|
+
products: ['emailMagicLinks'],
|
|
35
|
+
emailMagicLinksOptions: {
|
|
36
|
+
loginRedirectURL: 'https://example.com/authenticate',
|
|
37
|
+
loginExpirationMinutes: 30,
|
|
38
|
+
signupRedirectURL: 'https://example.com/authenticate',
|
|
39
|
+
signupExpirationMinutes: 30,
|
|
40
|
+
createUserAsPending: true,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
styles: {
|
|
44
|
+
container: { width: '321px' },
|
|
45
|
+
colors: { primary: '#0577CA' },
|
|
46
|
+
fontFamily: '"Helvetica New", Helvetica, sans-serif',
|
|
47
|
+
},
|
|
48
|
+
callbacks: {
|
|
49
|
+
onEvent: (message) => console.log(message),
|
|
50
|
+
onSuccess: (message) => console.log(message),
|
|
51
|
+
onError: (message) => console.log(message),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div id="login">
|
|
57
|
+
<StytchLogin
|
|
58
|
+
config={stytchProps.loginOrSignupView}
|
|
59
|
+
styles={stytchProps.styles}
|
|
60
|
+
callbacks={stytchProps.callbacks}
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Typescript Support
|
|
68
|
+
|
|
69
|
+
There are built in typescript definitions in the npm package.
|
|
70
|
+
|
|
71
|
+
## Migrating from @stytch/stytch-react
|
|
72
|
+
|
|
73
|
+
If you are migrating from [@stytch/stytch-react](https://www.npmjs.com/package/@stytch/stytch-react), follow the steps below:
|
|
74
|
+
|
|
75
|
+
### Step 1: Install the new libraries
|
|
76
|
+
|
|
77
|
+
- The core SDK is now bundled in its own module - [@stytch/vanilla-js](https://www.npmjs.com/package/@stytch/vanilla-js)
|
|
78
|
+
- We now have a library specifically for React bindings - [@stytch/react](https://www.npmjs.com/package/@stytch/react)
|
|
79
|
+
|
|
80
|
+
```shell
|
|
81
|
+
# NPM
|
|
82
|
+
npm install @stytch/vanilla-js @stytch/react
|
|
83
|
+
# Yarn
|
|
84
|
+
yarn add @stytch/vanilla-js @stytch/react
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Step 2: Remove the old SDK
|
|
88
|
+
|
|
89
|
+
- Remove the `@styth/stytch-react` package
|
|
90
|
+
- If you are explicitly loading the `stytch.js` script in the document header, remove it. It isn't needed anymore.
|
|
91
|
+
|
|
92
|
+
```shell
|
|
93
|
+
# NPM
|
|
94
|
+
npm rm @stytch/stytch-react
|
|
95
|
+
# Yarn
|
|
96
|
+
yarn remove @stytch/stytch-react
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Step 3: Initialize the client in your Application Root
|
|
100
|
+
|
|
101
|
+
- 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.
|
|
102
|
+
- To create the Stytch Headless client, use `StytchHeadlessClient` from `@stytch/vanilla-js/headless`
|
|
103
|
+
- To create the Stytch UI client, use `StytchUIClient` from `@stytch/vanilla-js`
|
|
104
|
+
- Pass it into `<StytchProvider />` component from `@stytch/react`
|
|
105
|
+
|
|
106
|
+
```jsx
|
|
107
|
+
import React from 'react';
|
|
108
|
+
import { StytchProvider } from '@stytch/react';
|
|
109
|
+
import { StytchHeadlessClient } from '@stytch/vanilla-js/headless';
|
|
110
|
+
// Or alternately
|
|
111
|
+
// import { StytchUIClient } from '@stytch/vanilla-js';
|
|
112
|
+
|
|
113
|
+
const stytch = new StytchHeadlessClient(process.env.REACT_APP_STYTCH_PUBLIC_TOKEN);
|
|
114
|
+
|
|
115
|
+
function WrappedApp() {
|
|
116
|
+
return (
|
|
117
|
+
<StytchProvider stytch={stytch}>
|
|
118
|
+
<App />
|
|
119
|
+
</StytchProvider>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default WrappedApp;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Step 4: Update calls to `useStytchUser` , `useStytchSession`, and `useStytchLazy`
|
|
127
|
+
|
|
128
|
+
- `useStytchUser` and `useStytchSession` hooks now return envelope objects - `{ user, isCached }` and `{ session, isCached }` respectively.
|
|
129
|
+
- On first render the SDK will read user/session out of persistent storage, and serve them with `isCached: true` - at this point you’re reading the stale-while-revalidating value
|
|
130
|
+
- The SDK will make network requests to pull the most up-to-date user and session objects, and serve them with `isCached: false`
|
|
131
|
+
- `useStytchLazy` is no longer required - you may always call `useStytch` now
|
|
132
|
+
|
|
133
|
+
```jsx
|
|
134
|
+
import React, { useEffect } from 'react';
|
|
135
|
+
import { useStytchUser } from '@stytch/react';
|
|
136
|
+
|
|
137
|
+
export default function Profile() {
|
|
138
|
+
const router = useRouter();
|
|
139
|
+
const { user, isCached } = useStytchUser();
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<Layout>
|
|
143
|
+
<h1>Your {isCached ? 'Cached' : null} Profile</h1>
|
|
144
|
+
<pre>{JSON.stringify(user, null, 2)}</pre>
|
|
145
|
+
</Layout>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Step 5: UI Naming Changes
|
|
151
|
+
|
|
152
|
+
We've made a number of small changes to our naming conventions to make the API cleaner and easier to understand.
|
|
153
|
+
|
|
154
|
+
- The `<Stytch />` login component is now called `<StytchLogin />`
|
|
155
|
+
- The `OAuthProvidersTypes` enum is now called `OAuthProviders`
|
|
156
|
+
- The `SDKProductTypes` enum is now called `Products`
|
|
157
|
+
- There are some additional changes to the `styles` config documented [here](https://stytch.com/docs/sdks/javascript-sdk#resources_migration-guide_v-zero-five)
|
package/b2b/package.json
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
import { Member, MemberSession, Organization, StytchB2BUIClient } from '@stytch/vanilla-js/b2b';
|
|
5
|
+
import { StytchB2BHeadlessClient } from '@stytch/vanilla-js/b2b/headless';
|
|
6
|
+
import { PermissionsMap } from '@stytch/core/public';
|
|
7
|
+
/**
|
|
8
|
+
* The Stytch Client object passed in to <StytchProvider /> in your application root.
|
|
9
|
+
*/
|
|
10
|
+
type StytchB2BClient = StytchB2BHeadlessClient | StytchB2BUIClient;
|
|
11
|
+
type SWRMember = {
|
|
12
|
+
/**
|
|
13
|
+
* Either the active {@link Member} object, or null if the member is not logged in.
|
|
14
|
+
*/
|
|
15
|
+
member: Member | null;
|
|
16
|
+
/**
|
|
17
|
+
* If true, indicates that the value returned is from the application cache and a state refresh is in progress.
|
|
18
|
+
*/
|
|
19
|
+
fromCache: boolean;
|
|
20
|
+
};
|
|
21
|
+
type SWRMemberSession = {
|
|
22
|
+
/**
|
|
23
|
+
* Either the active {@link MemberSession} object, or null if the member is not logged in.
|
|
24
|
+
*/
|
|
25
|
+
session: MemberSession | null;
|
|
26
|
+
/**
|
|
27
|
+
* If true, indicates that the value returned is from the application cache and a state refresh is in progress.
|
|
28
|
+
*/
|
|
29
|
+
fromCache: boolean;
|
|
30
|
+
};
|
|
31
|
+
type SWROrganization = {
|
|
32
|
+
/**
|
|
33
|
+
* Either the active {@link Organization} object, or null if the member is not logged in.
|
|
34
|
+
*/
|
|
35
|
+
organization: Organization | null;
|
|
36
|
+
/**
|
|
37
|
+
* If true, indicates that the value returned is from the application cache and a state refresh is in progress.
|
|
38
|
+
*/
|
|
39
|
+
fromCache: boolean;
|
|
40
|
+
};
|
|
41
|
+
declare const useIsMounted__INTERNAL: () => boolean;
|
|
42
|
+
declare const isUIClient: (client: StytchB2BClient) => client is StytchB2BUIClient;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the active Member.
|
|
45
|
+
* Check the fromCache property to determine if the member data is from persistent storage.
|
|
46
|
+
* @example
|
|
47
|
+
* const {member} = useStytchMember();
|
|
48
|
+
* return (<h1>Welcome, {member.name}</h1>);
|
|
49
|
+
* @returns A {@link SWRUser}
|
|
50
|
+
*/
|
|
51
|
+
declare const useStytchMember: () => SWRMember;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the active member's Stytch member session.
|
|
54
|
+
* @example
|
|
55
|
+
* const { session } = useStytchMemberSession();
|
|
56
|
+
* useEffect(() => {
|
|
57
|
+
* if (!session) {
|
|
58
|
+
* router.replace('/login')
|
|
59
|
+
* }
|
|
60
|
+
* }, [session]);
|
|
61
|
+
* @returns A {@link SWRMemberSession}
|
|
62
|
+
*/
|
|
63
|
+
declare const useStytchMemberSession: () => SWRMemberSession;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the active Stytch organization.
|
|
66
|
+
* @example
|
|
67
|
+
* const { organization } = useStytchOrganization();
|
|
68
|
+
* return organization ? <p>Welcome to {organization.organization_name}</p> : <p>Log in to continue!</p>;
|
|
69
|
+
* @returns A {@link SWROrganization}
|
|
70
|
+
*/
|
|
71
|
+
declare const useStytchOrganization: () => SWROrganization;
|
|
72
|
+
type SWRIsAuthorized = {
|
|
73
|
+
/**
|
|
74
|
+
* Whether the logged-in member is allowed to perform the specified action on the specified resource.
|
|
75
|
+
*/
|
|
76
|
+
isAuthorized: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* If true, indicates that the value returned is from the application cache and a state refresh is in progress.
|
|
79
|
+
*/
|
|
80
|
+
fromCache: boolean;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Determines whether the logged-in member is allowed to perform the specified action on the specified resource.
|
|
84
|
+
* Returns `true` if the member can perform the action, `false` otherwise.
|
|
85
|
+
*
|
|
86
|
+
* If the member is not logged in, this method will always return false.
|
|
87
|
+
* If the resource or action provided are not valid for the configured RBAC policy, this method will return false.
|
|
88
|
+
*
|
|
89
|
+
* Remember - authorization checks for sensitive actions should always occur on the backend as well.
|
|
90
|
+
* @example
|
|
91
|
+
* const isAuthorized = useStytchIsAuthorized<Permissions>('documents', 'edit');
|
|
92
|
+
* return <button disabled={!isAuthorized}>Edit</button>
|
|
93
|
+
*/
|
|
94
|
+
declare const useStytchIsAuthorized: (resourceId: string, action: string) => SWRIsAuthorized;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the Stytch B2B client stored in the Stytch context.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* const stytch = useStytchB2BClient();
|
|
100
|
+
* useEffect(() => {
|
|
101
|
+
* stytch.magicLinks.authenticate('...')
|
|
102
|
+
* }, [stytch]);
|
|
103
|
+
*/
|
|
104
|
+
declare const useStytchB2BClient: () => StytchB2BHeadlessClient;
|
|
105
|
+
declare const withStytchB2BClient: <T extends object>(Component: React.ComponentType<T & {
|
|
106
|
+
stytch: StytchB2BHeadlessClient;
|
|
107
|
+
}>) => React.ComponentType<T>;
|
|
108
|
+
declare const withStytchMember: <T extends object>(Component: React.ComponentType<T & {
|
|
109
|
+
stytchMember: Member | null;
|
|
110
|
+
stytchMemberIsFromCache: boolean;
|
|
111
|
+
}>) => React.ComponentType<T>;
|
|
112
|
+
declare const withStytchMemberSession: <T extends object>(Component: React.ComponentType<T & {
|
|
113
|
+
stytchMemberSession: MemberSession | null;
|
|
114
|
+
stytchMemberSessionIsFromCache: boolean;
|
|
115
|
+
}>) => React.ComponentType<T>;
|
|
116
|
+
declare const withStytchOrganization: <T extends object>(Component: React.ComponentType<T & {
|
|
117
|
+
stytchOrganization: Organization | null;
|
|
118
|
+
stytchOrganizationIsFromCache: boolean;
|
|
119
|
+
}>) => React.ComponentType<T>;
|
|
120
|
+
/**
|
|
121
|
+
* Wrap your component with this HOC in order to receive the permissions for the logged-in member.
|
|
122
|
+
* Evaluates all permissions granted to the logged-in member.
|
|
123
|
+
* Returns a Record<RoleId, Record<Action, boolean>> response indicating the member's permissions.
|
|
124
|
+
* Each boolean will be `true` if the member can perform the action, `false` otherwise.
|
|
125
|
+
*
|
|
126
|
+
* If the member is not logged in, all values will be false.
|
|
127
|
+
*
|
|
128
|
+
* Remember - authorization checks for sensitive actions should always occur on the backend as well.
|
|
129
|
+
* @example
|
|
130
|
+
* type Permissions = {
|
|
131
|
+
* document: 'create' | 'read' | 'write
|
|
132
|
+
* image: 'create' | 'read'
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* const MyComponent = (props) => {
|
|
136
|
+
* const canEditDocuments = props.stytchPermissions.document.edit;
|
|
137
|
+
* const canReadImages = props.stytchPermissions.image.read;
|
|
138
|
+
* }
|
|
139
|
+
* return withStytchPermissions<Permissions>(MyComponent)
|
|
140
|
+
*/
|
|
141
|
+
declare const withStytchPermissions: <Permissions_1 extends Record<string, string>, T extends object>(Component: React.ComponentType<T & {
|
|
142
|
+
stytchPermissions: PermissionsMap<Permissions_1>;
|
|
143
|
+
}>) => React.ComponentType<T>;
|
|
144
|
+
type StytchB2BProviderProps = {
|
|
145
|
+
/**
|
|
146
|
+
* A Stytch client instance {@link StytchB2BHeadlessClient}
|
|
147
|
+
*/
|
|
148
|
+
stytch: StytchB2BClient;
|
|
149
|
+
children?: ReactNode;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* The Stytch Context Provider.
|
|
153
|
+
* Wrap your application with this component in the root file in order to use Stytch everywhere in your app.
|
|
154
|
+
* @example
|
|
155
|
+
* const stytch = new StytchB2BHeadlessClient('public-token-<find yours in the stytch dashboard>')
|
|
156
|
+
*
|
|
157
|
+
* ReactDOM.render(
|
|
158
|
+
* <StytchB2BProvider stytch={stytch}>
|
|
159
|
+
* <App />
|
|
160
|
+
* </StytchProvider>,
|
|
161
|
+
* document.getElementById('root'),
|
|
162
|
+
* )
|
|
163
|
+
*/
|
|
164
|
+
declare const StytchB2BProvider: ({ stytch, children }: StytchB2BProviderProps) => JSX.Element;
|
|
165
|
+
export { useIsMounted__INTERNAL, isUIClient, useStytchMember, useStytchMemberSession, useStytchOrganization, useStytchIsAuthorized, useStytchB2BClient, withStytchB2BClient, withStytchMember, withStytchMemberSession, withStytchOrganization, withStytchPermissions, StytchB2BProviderProps, StytchB2BProvider };
|