@stytch/stytch-react 3.0.8-headless.beta.0 → 3.0.8-headless.beta.3

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { CallbackOptions, LoginOrSignupView, StyleConfig, StytchClient } from "@stytch/stytch-js";
2
+ import { CallbackOptions, LoginOrSignupView, StyleConfig, Session, StytchClient, User, WebAuthnAuthenticateOptions, WebAuthnAuthenticateResponse, WebAuthnRegisterResponse } from "@stytch/stytch-js";
3
3
  import React from "react";
4
4
  import { ReactNode } from "react";
5
5
  interface StytchProps {
@@ -14,17 +14,14 @@ interface StytchProps {
14
14
  * [Documentation](https://stytch.com/docs/javascript-sdk)
15
15
  */
16
16
  declare const Stytch: ({ publicToken, style, callbacks, loginOrSignupView }: StytchProps) => JSX.Element;
17
- type User = {
18
- user_id: string;
19
- };
20
- type Session = {
21
- session_id: string;
22
- expires_at: string;
23
- };
24
17
  declare const useStytchUser: () => User | null;
25
18
  declare const useStytchSession: () => Session | null;
26
- declare const useStytch: () => StytchClient | null;
19
+ declare const useStytch: () => StytchClient;
20
+ declare const useStytchLazy: () => StytchClient;
27
21
  declare const withStytch: <T extends object>(Component: React.ComponentType<T & {
22
+ stytch: StytchClient;
23
+ }>) => React.ComponentType<T>;
24
+ declare const withStytchLazy: <T extends object>(Component: React.ComponentType<T & {
28
25
  stytch: StytchClient | null;
29
26
  }>) => React.ComponentType<T>;
30
27
  declare const withStytchUser: <T extends object>(Component: React.ComponentType<T & {
@@ -34,9 +31,29 @@ declare const withStytchSession: <T extends object>(Component: React.ComponentTy
34
31
  stytchSession: Session | null;
35
32
  }>) => React.ComponentType<T>;
36
33
  type StytchProviderProps = {
37
- publicToken: string;
34
+ stytch: StytchClient | null | Promise<StytchClient | null>;
38
35
  children?: ReactNode;
39
36
  };
40
- declare const StytchProvider: ({ publicToken, children }: StytchProviderProps) => JSX.Element;
41
- export { SDKProductTypes, OneTapPositions, OAuthProvidersTypes, StytchClient } from '@stytch/stytch-js';
42
- export { Stytch, StytchProps, StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser };
37
+ declare const StytchProvider: ({ stytch, children }: StytchProviderProps) => JSX.Element;
38
+ type StytchWebAuthnRegisterLoading = {
39
+ isLoading: true;
40
+ register(): undefined;
41
+ };
42
+ type StytchWebAuthnRegisterLoaded = {
43
+ isLoading: false;
44
+ register(): Promise<WebAuthnRegisterResponse>;
45
+ };
46
+ type StytchWebAuthnRegister = StytchWebAuthnRegisterLoading | StytchWebAuthnRegisterLoaded;
47
+ declare const useStytchWebAuthnRegister: () => StytchWebAuthnRegister;
48
+ type StytchWebAuthnAuthenticateLoading = {
49
+ isLoading: true;
50
+ authenticate(): undefined;
51
+ };
52
+ type StytchWebAuthnAuthenticateLoaded = {
53
+ isLoading: false;
54
+ authenticate(): Promise<WebAuthnAuthenticateResponse>;
55
+ };
56
+ type StytchWebAuthnAuthenticate = StytchWebAuthnAuthenticateLoading | StytchWebAuthnAuthenticateLoaded;
57
+ declare const useStytchWebAuthnAuthenticate: (options: WebAuthnAuthenticateOptions) => StytchWebAuthnAuthenticate;
58
+ export * from '@stytch/stytch-js';
59
+ export { Stytch, StytchProps, StytchProvider, StytchProviderProps, useStytch, useStytchLazy, useStytchSession, useStytchUser, withStytch, withStytchLazy, withStytchSession, withStytchUser, StytchWebAuthnAuthenticate, StytchWebAuthnRegister, useStytchWebAuthnAuthenticate, useStytchWebAuthnRegister };
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { CallbackOptions, LoginOrSignupView, StyleConfig, StytchClient } from "@stytch/stytch-js";
2
+ import { CallbackOptions, LoginOrSignupView, StyleConfig, Session, StytchClient, User, WebAuthnAuthenticateOptions, WebAuthnAuthenticateResponse, WebAuthnRegisterResponse } from "@stytch/stytch-js";
3
3
  import React from "react";
4
4
  import { ReactNode } from "react";
5
5
  interface StytchProps {
@@ -14,17 +14,14 @@ interface StytchProps {
14
14
  * [Documentation](https://stytch.com/docs/javascript-sdk)
15
15
  */
16
16
  declare const Stytch: ({ publicToken, style, callbacks, loginOrSignupView }: StytchProps) => JSX.Element;
17
- type User = {
18
- user_id: string;
19
- };
20
- type Session = {
21
- session_id: string;
22
- expires_at: string;
23
- };
24
17
  declare const useStytchUser: () => User | null;
25
18
  declare const useStytchSession: () => Session | null;
26
- declare const useStytch: () => StytchClient | null;
19
+ declare const useStytch: () => StytchClient;
20
+ declare const useStytchLazy: () => StytchClient;
27
21
  declare const withStytch: <T extends object>(Component: React.ComponentType<T & {
22
+ stytch: StytchClient;
23
+ }>) => React.ComponentType<T>;
24
+ declare const withStytchLazy: <T extends object>(Component: React.ComponentType<T & {
28
25
  stytch: StytchClient | null;
29
26
  }>) => React.ComponentType<T>;
30
27
  declare const withStytchUser: <T extends object>(Component: React.ComponentType<T & {
@@ -34,9 +31,29 @@ declare const withStytchSession: <T extends object>(Component: React.ComponentTy
34
31
  stytchSession: Session | null;
35
32
  }>) => React.ComponentType<T>;
36
33
  type StytchProviderProps = {
37
- publicToken: string;
34
+ stytch: StytchClient | null | Promise<StytchClient | null>;
38
35
  children?: ReactNode;
39
36
  };
40
- declare const StytchProvider: ({ publicToken, children }: StytchProviderProps) => JSX.Element;
41
- export { SDKProductTypes, OneTapPositions, OAuthProvidersTypes, StytchClient } from '@stytch/stytch-js';
42
- export { Stytch, StytchProps, StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser };
37
+ declare const StytchProvider: ({ stytch, children }: StytchProviderProps) => JSX.Element;
38
+ type StytchWebAuthnRegisterLoading = {
39
+ isLoading: true;
40
+ register(): undefined;
41
+ };
42
+ type StytchWebAuthnRegisterLoaded = {
43
+ isLoading: false;
44
+ register(): Promise<WebAuthnRegisterResponse>;
45
+ };
46
+ type StytchWebAuthnRegister = StytchWebAuthnRegisterLoading | StytchWebAuthnRegisterLoaded;
47
+ declare const useStytchWebAuthnRegister: () => StytchWebAuthnRegister;
48
+ type StytchWebAuthnAuthenticateLoading = {
49
+ isLoading: true;
50
+ authenticate(): undefined;
51
+ };
52
+ type StytchWebAuthnAuthenticateLoaded = {
53
+ isLoading: false;
54
+ authenticate(): Promise<WebAuthnAuthenticateResponse>;
55
+ };
56
+ type StytchWebAuthnAuthenticate = StytchWebAuthnAuthenticateLoading | StytchWebAuthnAuthenticateLoaded;
57
+ declare const useStytchWebAuthnAuthenticate: (options: WebAuthnAuthenticateOptions) => StytchWebAuthnAuthenticate;
58
+ export * from '@stytch/stytch-js';
59
+ export { Stytch, StytchProps, StytchProvider, StytchProviderProps, useStytch, useStytchLazy, useStytchSession, useStytchUser, withStytch, withStytchLazy, withStytchSession, withStytchUser, StytchWebAuthnAuthenticate, StytchWebAuthnRegister, useStytchWebAuthnAuthenticate, useStytchWebAuthnRegister };
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { createContext, useContext, useState, useEffect } from 'react';
1
+ import React, { useRef, useState, useEffect, useCallback, createContext, useContext, useMemo } from 'react';
2
2
 
3
3
  var PUBLIC_URL = 'https://js.stytch.com/stytch.js';
4
4
  function getJSUrl() {
@@ -102,6 +102,41 @@ var OneTapPositions;
102
102
  OneTapPositions["floating"] = "floating";
103
103
  })(OneTapPositions || (OneTapPositions = {}));
104
104
 
105
+ var initStytch = function () {
106
+ var args = [];
107
+ for (var _i = 0; _i < arguments.length; _i++) {
108
+ args[_i] = arguments[_i];
109
+ }
110
+ if (typeof window === 'undefined') {
111
+ return null;
112
+ }
113
+ if (!window.Stytch) {
114
+ throw new Error('Stytch has not been loaded.');
115
+ }
116
+ return window.Stytch.apply(window, args);
117
+ };
118
+ var loadAndInitStytch = function () {
119
+ var args = [];
120
+ for (var _i = 0; _i < arguments.length; _i++) {
121
+ args[_i] = arguments[_i];
122
+ }
123
+ return loadStytch().then(function (stytchFactory) { return stytchFactory && stytchFactory.apply(void 0, args); });
124
+ };
125
+
126
+ // useState can cause memory leaks if it is set after the component unmounted. For example, if it is
127
+ // set after `await`, or in a `then`, `catch`, or `finally`, or in a setTimout/setInterval.
128
+ var useAsyncState = function (initialState) {
129
+ var isMounted = useRef(true);
130
+ var _a = useState(initialState), state = _a[0], setState = _a[1];
131
+ useEffect(function () { return function () {
132
+ isMounted.current = false;
133
+ }; }, []);
134
+ var setStateAction = useCallback(function (newState) {
135
+ isMounted.current && setState(newState);
136
+ }, []);
137
+ return [state, setStateAction];
138
+ };
139
+
105
140
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
141
  function invariant(cond, message) {
107
142
  if (!cond)
@@ -132,35 +167,98 @@ var __assign = function() {
132
167
  return t;
133
168
  };
134
169
  return __assign.apply(this, arguments);
170
+ };
171
+
172
+ function __awaiter(thisArg, _arguments, P, generator) {
173
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
174
+ return new (P || (P = Promise))(function (resolve, reject) {
175
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
176
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
177
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
178
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
179
+ });
180
+ }
181
+
182
+ function __generator(thisArg, body) {
183
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
184
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
185
+ function verb(n) { return function (v) { return step([n, v]); }; }
186
+ function step(op) {
187
+ if (f) throw new TypeError("Generator is already executing.");
188
+ while (_) try {
189
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
190
+ if (y = 0, t) op = [op[0] & 2, t.value];
191
+ switch (op[0]) {
192
+ case 0: case 1: t = op; break;
193
+ case 4: _.label++; return { value: op[1], done: false };
194
+ case 5: _.label++; y = op[1]; op = [0]; continue;
195
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
196
+ default:
197
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
198
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
199
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
200
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
201
+ if (t[2]) _.ops.pop();
202
+ _.trys.pop(); continue;
203
+ }
204
+ op = body.call(thisArg, _);
205
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
206
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
207
+ }
208
+ }
209
+
210
+ var noProviderError = function (hookOrHOC) { return "".concat(hookOrHOC, " can only be used inside <StytchProvider>."); };
211
+ var lazyError = function (hookOrHOC) {
212
+ return "".concat(hookOrHOC, " can only be used if Stytch is preloaded. Add <script src=\"https://js.stytch.com/stytch.js\" /> in your document header to load the script synchronously, or use ").concat(hookOrHOC, "Lazy if you want to lazy load Stytch. If you are using SSR, you will need to use ").concat(hookOrHOC, "Lazy.");
135
213
  };
136
214
 
137
- var StytchMountedContext = createContext(false);
215
+ var StytchMountedContext = createContext({
216
+ isLazy: false,
217
+ isMounted: false,
218
+ });
138
219
  var StytchUserContext = createContext(null);
139
220
  var StytchSessionContext = createContext(null);
140
221
  var StytchContext = createContext(null);
141
- var useStytchMounted__INTERNAL = function () { return useContext(StytchMountedContext); };
222
+ var useIsMounted__INTERNAL = function () { return useContext(StytchMountedContext).isMounted; };
223
+ var useIsLazy__INTERNAL = function () { return useContext(StytchMountedContext).isLazy; };
142
224
  var useStytchRaw__INTERNAL = function () { return useContext(StytchContext); };
143
225
  var useStytchUser = function () {
144
- invariant(useStytchMounted__INTERNAL(), 'useStytchUser/withStytchUser can only be used inside <StytchProvider>.');
226
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchUser'));
145
227
  return useContext(StytchUserContext);
146
228
  };
147
229
  var useStytchSession = function () {
148
- invariant(useStytchMounted__INTERNAL(), 'useStytchSession/withStytchSession can only be used inside <StytchProvider>.');
230
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchSession'));
149
231
  return useContext(StytchSessionContext);
150
232
  };
151
233
  var useStytch = function () {
152
- invariant(useStytchMounted__INTERNAL(), 'useStytch/withStytch can only be used inside <StytchProvider>.');
234
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytch'));
235
+ invariant(!useIsLazy__INTERNAL(), lazyError('useStytch'));
236
+ return useContext(StytchContext);
237
+ };
238
+ var useStytchLazy = function () {
239
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchLazy'));
153
240
  return useContext(StytchContext);
154
241
  };
155
242
  var withStytch = function (Component) {
156
243
  var WithStytch = function (props) {
244
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytch'));
245
+ invariant(!useIsLazy__INTERNAL(), lazyError('withStytch'));
157
246
  return React.createElement(Component, __assign({}, props, { stytch: useStytch() }));
158
247
  };
159
248
  WithStytch.displayName = "withStytch(".concat(Component.displayName || Component.name || 'Component', ")");
160
249
  return WithStytch;
161
250
  };
251
+ var withStytchLazy = function (Component) {
252
+ var WithStytchLazy = function (props) {
253
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchLazy'));
254
+ return React.createElement(Component, __assign({}, props, { stytch: useStytchLazy() }));
255
+ };
256
+ WithStytchLazy.displayName = "withStytchLazy(".concat(Component.displayName || Component.name || 'Component', ")");
257
+ return WithStytchLazy;
258
+ };
162
259
  var withStytchUser = function (Component) {
163
260
  var WithStytchUser = function (props) {
261
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchUser'));
164
262
  return React.createElement(Component, __assign({}, props, { stytchUser: useStytchUser() }));
165
263
  };
166
264
  WithStytchUser.displayName = "withStytchUser(".concat(Component.displayName || Component.name || 'Component', ")");
@@ -168,56 +266,45 @@ var withStytchUser = function (Component) {
168
266
  };
169
267
  var withStytchSession = function (Component) {
170
268
  var WithStytchSession = function (props) {
269
+ invariant(useIsMounted__INTERNAL(), noProviderError('withStytchSession'));
171
270
  return React.createElement(Component, __assign({}, props, { stytchSession: useStytchSession() }));
172
271
  };
173
272
  WithStytchSession.displayName = "withStytchSession(".concat(Component.displayName || Component.name || 'Component', ")");
174
273
  return WithStytchSession;
175
274
  };
176
- var LOCAL_STORAGE_KEY_PREFIX = 'stytch_state_';
177
- var getLocalStorageKey = function (type, publicToken) {
178
- return "".concat(LOCAL_STORAGE_KEY_PREFIX).concat(publicToken, "_").concat(type);
179
- };
180
- var getLocalStorageSession = function (publicToken) {
181
- if (typeof localStorage === 'undefined')
182
- return null;
183
- var sessionString = localStorage.getItem(getLocalStorageKey('session', publicToken));
184
- var session = JSON.parse(sessionString);
185
- if (session && Date.parse(session.expires_at) > Date.now()) {
186
- return session;
187
- }
188
- return null;
189
- };
190
- var getLocalStorageUser = function (publicToken) {
191
- if (typeof localStorage === 'undefined')
192
- return null;
193
- if (getLocalStorageSession(publicToken)) {
194
- var userString = localStorage.getItem(getLocalStorageKey('user', publicToken));
195
- return userString ? JSON.parse(userString) : null;
196
- }
197
- return null;
198
- };
199
275
  var StytchProvider = function (_a) {
200
- var publicToken = _a.publicToken, children = _a.children;
201
- invariant(!useStytchMounted__INTERNAL(), 'You cannot render a <StytchProvider> inside another <StytchProvider>.');
202
- invariant(publicToken, 'publicToken not provided to <StytchProvider>.');
203
- var _b = useState(typeof window !== 'undefined' && window.Stytch ? window.Stytch(publicToken) : null), stytchClient = _b[0], setStytchClient = _b[1];
204
- var _c = useState(stytchClient ? stytchClient.user.getSync() : getLocalStorageUser(publicToken)), user = _c[0], setUser = _c[1];
205
- var _d = useState(stytchClient ? stytchClient.session.getSync() : getLocalStorageSession(publicToken)), session = _d[0], setSession = _d[1];
276
+ var stytch = _a.stytch, children = _a.children;
277
+ invariant(!useIsMounted__INTERNAL(), 'You cannot render a <StytchProvider> inside another <StytchProvider>.');
278
+ var _b = useState(stytch instanceof Promise || !stytch ? null : stytch), stytchClient = _b[0], setStytchClient = _b[1];
279
+ var mountedContext = useState({
280
+ isLazy: !stytchClient,
281
+ isMounted: true,
282
+ })[0];
283
+ var _c = useAsyncState(stytchClient && stytchClient.user.getSync()), user = _c[0], setUser = _c[1];
284
+ var _d = useAsyncState(stytchClient && stytchClient.session.getSync()), session = _d[0], setSession = _d[1];
206
285
  useEffect(function () {
207
- if (!stytchClient) {
208
- loadStytch().then(function (globalStytch) { return globalStytch && setStytchClient(globalStytch(publicToken)); });
286
+ if (stytch instanceof Promise) {
287
+ stytch.then(setStytchClient);
209
288
  }
210
- }, [stytchClient, publicToken]);
289
+ }, [stytch]);
211
290
  useEffect(function () {
212
291
  if (stytchClient) {
213
- stytchClient.user.onChange(setUser);
214
- stytchClient.session.onChange(setSession);
292
+ if (mountedContext.isLazy) {
293
+ setUser(stytchClient.user.getSync());
294
+ setSession(stytchClient.session.getSync());
295
+ }
296
+ var unsubscribeUser_1 = stytchClient.user.onChange(setUser);
297
+ var unsubscribeSession_1 = stytchClient.session.onChange(setSession);
298
+ return function () {
299
+ unsubscribeUser_1();
300
+ unsubscribeSession_1();
301
+ };
215
302
  }
216
- }, [stytchClient]);
217
- return (React.createElement(StytchMountedContext.Provider, { value: true },
303
+ }, [mountedContext, stytchClient, setUser, setSession]);
304
+ return (React.createElement(StytchMountedContext.Provider, { value: mountedContext },
218
305
  React.createElement(StytchContext.Provider, { value: stytchClient },
219
- React.createElement(StytchUserContext.Provider, { value: user },
220
- React.createElement(StytchSessionContext.Provider, { value: session }, children)))));
306
+ React.createElement(StytchUserContext.Provider, { value: session && user },
307
+ React.createElement(StytchSessionContext.Provider, { value: user && session }, children)))));
221
308
  };
222
309
 
223
310
  /**
@@ -242,8 +329,8 @@ var useUniqueElementId = function () {
242
329
  var Stytch = function (_a) {
243
330
  var publicToken = _a.publicToken, style = _a.style, callbacks = _a.callbacks, loginOrSignupView = _a.loginOrSignupView;
244
331
  var stytchClientFromContext = useStytchRaw__INTERNAL();
245
- var stytchMounted = useStytchMounted__INTERNAL();
246
- var _b = useState(function () {
332
+ var stytchMounted = useIsMounted__INTERNAL();
333
+ var _b = useAsyncState(function () {
247
334
  // If StytchProvider has been mounted, use context value
248
335
  if (stytchMounted) {
249
336
  return stytchClientFromContext;
@@ -267,7 +354,7 @@ var Stytch = function (_a) {
267
354
  setStytchClient(stytchClientFromContext);
268
355
  }
269
356
  }
270
- }, [stytchClient, stytchClientFromContext, stytchMounted, publicToken]);
357
+ }, [stytchClient, stytchClientFromContext, stytchMounted, publicToken, setStytchClient]);
271
358
  useEffect(function () {
272
359
  if (!stytchClient || !elementId) {
273
360
  return;
@@ -283,5 +370,74 @@ var Stytch = function (_a) {
283
370
  return elementId ? React.createElement("div", { id: elementId }) : null;
284
371
  };
285
372
 
286
- export { OAuthProvidersTypes, OneTapPositions, SDKProductTypes, Stytch, StytchProvider, useStytch, useStytchSession, useStytchUser, withStytch, withStytchSession, withStytchUser };
373
+ var useStytchWebAuthnRegister = function () {
374
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchWebAuthnRegister'));
375
+ var _a = useAsyncState(null), creationOptions = _a[0], setCreationOptions = _a[1];
376
+ var stytchClient = useStytchRaw__INTERNAL();
377
+ useEffect(function () {
378
+ var registerStart = function () { return __awaiter(void 0, void 0, void 0, function () {
379
+ var resp;
380
+ return __generator(this, function (_a) {
381
+ switch (_a.label) {
382
+ case 0:
383
+ if (!stytchClient) return [3 /*break*/, 2];
384
+ return [4 /*yield*/, stytchClient.webauthn.registerStart()];
385
+ case 1:
386
+ resp = _a.sent();
387
+ setCreationOptions(resp.public_key_credential_creation_options);
388
+ _a.label = 2;
389
+ case 2: return [2 /*return*/];
390
+ }
391
+ });
392
+ }); };
393
+ registerStart();
394
+ }, [stytchClient, setCreationOptions]);
395
+ return useMemo(function () {
396
+ return creationOptions
397
+ ? {
398
+ isLoading: false,
399
+ register: function () { return stytchClient.webauthn.register(creationOptions); },
400
+ }
401
+ : {
402
+ isLoading: true,
403
+ register: function () { return undefined; },
404
+ };
405
+ }, [creationOptions, stytchClient]);
406
+ };
407
+ var useStytchWebAuthnAuthenticate = function (options) {
408
+ invariant(useIsMounted__INTERNAL(), noProviderError('useStytchWebAuthnAuthenticate'));
409
+ var _a = useAsyncState(null), requestOptions = _a[0], setRequestOptions = _a[1];
410
+ var stytchClient = useStytchRaw__INTERNAL();
411
+ useEffect(function () {
412
+ var authenticateStart = function () { return __awaiter(void 0, void 0, void 0, function () {
413
+ var resp;
414
+ return __generator(this, function (_a) {
415
+ switch (_a.label) {
416
+ case 0:
417
+ if (!stytchClient) return [3 /*break*/, 2];
418
+ return [4 /*yield*/, stytchClient.webauthn.authenticateStart()];
419
+ case 1:
420
+ resp = _a.sent();
421
+ setRequestOptions(resp.public_key_credential_request_options);
422
+ _a.label = 2;
423
+ case 2: return [2 /*return*/];
424
+ }
425
+ });
426
+ }); };
427
+ authenticateStart();
428
+ }, [stytchClient, setRequestOptions]);
429
+ return useMemo(function () {
430
+ return requestOptions
431
+ ? {
432
+ authenticate: function () { return stytchClient.webauthn.authenticate(requestOptions, options); },
433
+ isLoading: false,
434
+ }
435
+ : {
436
+ authenticate: function () { return undefined; },
437
+ isLoading: true,
438
+ };
439
+ }, [requestOptions, options, stytchClient]);
440
+ };
441
+
442
+ export { CallbackEventType, EventType, OAuthProvidersTypes, OneTapPositions, SDKProductTypes, Stytch, StytchProvider, initStytch, loadAndInitStytch, loadStytch, useStytch, useStytchLazy, useStytchSession, useStytchUser, useStytchWebAuthnAuthenticate, useStytchWebAuthnRegister, withStytch, withStytchLazy, withStytchSession, withStytchUser };
287
443
  //# sourceMappingURL=index.esm.js.map