@descope/react-sdk 3.0.4 → 3.1.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 +21 -5
- package/dist/cjs/components/AccessKeyManagement.js.map +1 -1
- package/dist/cjs/components/Descope.js.map +1 -1
- package/dist/cjs/constants.js +1 -1
- package/dist/esm/components/AccessKeyManagement.js.map +1 -1
- package/dist/esm/components/Descope.js.map +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -291,7 +291,7 @@ const App = () => {
|
|
|
291
291
|
// NOTE - `useDescope`, `useSession`, `useUser` should be used inside `AuthProvider` context,
|
|
292
292
|
// and will throw an exception if this requirement is not met
|
|
293
293
|
// useSession retrieves authentication state, session loading status, useful claims, and the session token
|
|
294
|
-
//
|
|
294
|
+
// Use `isAuthenticated` to check whether there is an active session - not `sessionToken`
|
|
295
295
|
const { isAuthenticated, isSessionLoading, sessionToken, claims } = useSession();
|
|
296
296
|
// useUser retrieves the logged in user information
|
|
297
297
|
const { user, isUserLoading } = useUser();
|
|
@@ -320,6 +320,24 @@ const App = () => {
|
|
|
320
320
|
};
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
+
> **Important:** always use `isAuthenticated` to determine whether there is an active session - never `sessionToken`.
|
|
324
|
+
>
|
|
325
|
+
> `sessionToken` is empty whenever the session token is not accessible to client-side code, for example when the Descope project is [configured to manage the session token in cookies](#3-configure-descope-project-to-manage-session-token-in-cookies) (`Secure` + `HttpOnly` `DS` cookie), or when `persistTokens={false}` is set. In those setups the user is fully authenticated while `sessionToken` is an empty string, so guarding logic on it silently skips that logic:
|
|
326
|
+
>
|
|
327
|
+
> ```js
|
|
328
|
+
> // WRONG - skipped for authenticated users when the session token lives in an HttpOnly cookie
|
|
329
|
+
> if (!sessionToken && !isSessionLoading) {
|
|
330
|
+
> return; // e.g. bailing out before calling sdk.logout()
|
|
331
|
+
> }
|
|
332
|
+
>
|
|
333
|
+
> // CORRECT
|
|
334
|
+
> if (!isAuthenticated && !isSessionLoading) {
|
|
335
|
+
> return;
|
|
336
|
+
> }
|
|
337
|
+
> ```
|
|
338
|
+
>
|
|
339
|
+
> `isAuthenticated` is derived from the session's expiration, which the SDK receives in every token-storage mode. Read `sessionToken` only when you actually need the raw JWT (for example to attach it to an API request), and use `claims` to read claims out of the session.
|
|
340
|
+
|
|
323
341
|
### Trigger Auto Refresh
|
|
324
342
|
|
|
325
343
|
`useSession` triggers a single request to the Descope backend to attempt to refresh the session. If you **don't** `useSession` in your app, the session will not be refreshed automatically. If your app does not require `useSession`, you can trigger the refresh manually by calling `refresh` from `useDescope` hook. Example:
|
|
@@ -489,10 +507,8 @@ If you need to customize this, you can set `sessionTokenViaCookie={{sameSite: 'L
|
|
|
489
507
|
|
|
490
508
|
If project settings are configured to manage session token in cookies, Descope services will automatically set the session token in the `DS` cookie as a `Secure` and `HttpOnly` cookie. In this case, the session token will not be stored in the browser's and will not be accessible to the client-side code using `useSession` or `getSessionToken`.
|
|
491
509
|
|
|
492
|
-
However, `useSession`'s returned `claims`
|
|
493
|
-
from the token.
|
|
510
|
+
However, `useSession`'s returned `isAuthenticated` and `claims` fields are always available - `isAuthenticated` still reflects the active session, and `claims` still exposes custom claims & common Descope claims from the token. Make sure your app checks authentication state with `isAuthenticated` and not with `sessionToken`, which will be empty in this mode.
|
|
494
511
|
|
|
495
|
-
````js
|
|
496
512
|
### Helper Functions
|
|
497
513
|
|
|
498
514
|
You can also use the following functions to assist with various actions managing your JWT.
|
|
@@ -546,7 +562,7 @@ const AppRoot = () => {
|
|
|
546
562
|
</AuthProvider>
|
|
547
563
|
);
|
|
548
564
|
};
|
|
549
|
-
|
|
565
|
+
```
|
|
550
566
|
|
|
551
567
|
### Custom Storage
|
|
552
568
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccessKeyManagement.js","sources":["../../../src/components/AccessKeyManagement.tsx"],"sourcesContent":["import React, {\n lazy,\n Suspense,\n useImperativeHandle,\n useState,\n useEffect,\n} from 'react';\nimport Context from '../hooks/Context';\nimport { AccessKeyManagementProps } from '../types';\nimport withPropsMapping from './withPropsMapping';\n\n// web-component code uses browser API, but can be used in SSR apps, hence the lazy loading\nconst AccessKeyManagementWC = lazy(async () => {\n await import('@descope/access-key-management-widget');\n\n return {\n default: withPropsMapping(\n React.forwardRef<HTMLElement>((props, ref) => (\n
|
|
1
|
+
{"version":3,"file":"AccessKeyManagement.js","sources":["../../../src/components/AccessKeyManagement.tsx"],"sourcesContent":["import React, {\n lazy,\n Suspense,\n useImperativeHandle,\n useState,\n useEffect,\n} from 'react';\nimport Context from '../hooks/Context';\nimport { AccessKeyManagementProps } from '../types';\nimport withPropsMapping from './withPropsMapping';\n\n// web-component code uses browser API, but can be used in SSR apps, hence the lazy loading\nconst AccessKeyManagementWC = lazy(async () => {\n await import('@descope/access-key-management-widget');\n\n return {\n default: withPropsMapping(\n React.forwardRef<HTMLElement>((props, ref) => (\n\t<descope-access-key-management-widget ref={ref} {...props} />\n )),\n ),\n };\n});\n\nconst AccessKeyManagement = React.forwardRef<\n HTMLElement,\n AccessKeyManagementProps\n>(\n (\n { logger, tenant, theme, locale, debug, widgetId, styleId, onReady },\n ref,\n ) => {\n const [innerRef, setInnerRef] = useState(null);\n\n useImperativeHandle(ref, () => innerRef);\n\n const { projectId, baseUrl, baseStaticUrl, baseCdnUrl, refreshCookieName } =\n React.useContext(Context);\n\n useEffect(() => {\n const ele = innerRef;\n if (onReady) ele?.addEventListener('ready', onReady);\n\n return () => {\n if (onReady) ele?.removeEventListener('ready', onReady);\n };\n }, [innerRef, onReady]);\n\n return (\n\t<Suspense fallback={null}>\n\t\t<AccessKeyManagementWC\n ref={setInnerRef}\n projectId={projectId}\n widgetId={widgetId}\n tenant={tenant}\n baseUrl={baseUrl}\n baseStaticUrl={baseStaticUrl}\n baseCdnUrl={baseCdnUrl}\n {...{\n // attributes\n 'theme.attr': theme,\n 'locale.attr': locale,\n 'debug.attr': debug,\n 'styleId.attr': styleId,\n 'refreshCookieName.attr': refreshCookieName,\n // props\n 'logger.prop': logger,\n }}\n />\n\t</Suspense>\n );\n },\n);\n\nexport default AccessKeyManagement;\n"],"names":["AccessKeyManagementWC","lazy","async","import","default","withPropsMapping","React","forwardRef","props","ref","createElement","Object","assign","AccessKeyManagement","logger","tenant","theme","locale","debug","widgetId","styleId","onReady","innerRef","setInnerRef","useState","useImperativeHandle","projectId","baseUrl","baseStaticUrl","baseCdnUrl","refreshCookieName","useContext","Context","useEffect","ele","addEventListener","removeEventListener","Suspense","fallback"],"mappings":"mOAYA,MAAMA,EAAwBC,EAAIA,MAACC,gBAC3BC,OAAO,yCAEN,CACLC,QAASC,EAAgBD,QACvBE,UAAMC,YAAwB,CAACC,EAAOC,IAC3CH,EAAAA,QAAsCI,cAAA,uCAAAC,OAAAC,OAAA,CAAAH,IAAKA,GAASD,WAM/CK,EAAsBP,EAAAA,QAAMC,YAIhC,EACIO,SAAQC,SAAQC,QAAOC,SAAQC,QAAOC,WAAUC,UAASC,WAC3DZ,KAEA,MAAOa,EAAUC,GAAeC,EAAQA,SAAC,MAEzCC,sBAAoBhB,GAAK,IAAMa,IAE/B,MAAMI,UAAEA,EAASC,QAAEA,EAAOC,cAAEA,EAAaC,WAAEA,EAAUC,kBAAEA,GACrDxB,EAAKF,QAAC2B,WAAWC,EAAAA,SAWnB,OATAC,EAAAA,WAAU,KACR,MAAMC,EAAMZ,EAGZ,OAFID,IAASa,SAAAA,EAAKC,iBAAiB,QAASd,IAErC,KACDA,IAASa,SAAAA,EAAKE,oBAAoB,QAASf,GAAQ,CACxD,GACA,CAACC,EAAUD,IAGjBf,EAACF,QAAAM,cAAA2B,EAAQA,SAAC,CAAAC,SAAU,MACnBhC,EAAAF,QAAAM,cAACV,EAAqB,CACdS,IAAKc,EACLG,UAAWA,EACXP,SAAUA,EACVJ,OAAQA,EACRY,QAASA,EACTC,cAAeA,EACfC,WAAYA,EAGV,aAAcb,EACd,cAAeC,EACf,aAAcC,EACd,eAAgBE,EAChB,yBAA0BU,EAE1B,cAAehB,IAIrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Descope.js","sources":["../../../src/components/Descope.tsx"],"sourcesContent":["/* eslint-disable react/prop-types */\nimport React, {\n lazy,\n Suspense,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react';\nimport { baseHeaders } from '../constants';\nimport Context from '../hooks/Context';\nimport { DescopeProps } from '../types';\nimport { getGlobalSdk } from '../sdk';\nimport withPropsMapping from './withPropsMapping';\n\n// web-component code uses browser API, but can be used in SSR apps, hence the lazy loading\nconst DescopeWC = lazy(async () => {\n const updateDynamicHeader = (key: string, value: string) => {\n if (value) {\n baseHeaders[key] = value;\n } else {\n delete baseHeaders[key];\n }\n };\n\n const WebComponent: any =\n customElements?.get('descope-wc') ||\n (await import('@descope/web-component').then((module) => module.default));\n\n WebComponent.sdkConfigOverrides = {\n // Overrides the web-component's base headers to indicate usage via the React SDK\n baseHeaders,\n // Disables token persistence within the web-component to delegate token management\n // to the global SDK hooks. This ensures token handling aligns with the SDK's configuration,\n // and web-component requests leverage the global SDK's beforeRequest hooks for consistency\n persistTokens: false,\n hooks: {\n get beforeRequest() {\n // Retrieves the beforeRequest hook from the global SDK, which is initialized\n // within the AuthProvider using the desired configuration. This approach ensures\n // the web-component utilizes the same beforeRequest hooks as the global SDK\n return getGlobalSdk().httpClient.hooks.beforeRequest;\n },\n set beforeRequest(_) {\n // The empty setter prevents runtime errors when attempts are made to assign a value to 'beforeRequest'.\n // JavaScript objects default to having both getters and setters\n },\n },\n };\n\n return {\n default: withPropsMapping(\n React.forwardRef<HTMLElement>(\n ({ 'external-request-id': externalRequestId, ...props }: any, ref) => {\n // update the dynamic headers with the external request ID if provided\n useMemo(() => {\n updateDynamicHeader('x-external-rid', externalRequestId);\n }, [externalRequestId]);\n\n return <descope-wc ref={ref} {...props} />;\n },\n ),\n ),\n };\n});\n\nconst Descope = React.forwardRef<HTMLElement, DescopeProps>(\n (\n {\n flowId,\n onSuccess,\n onError,\n onReady,\n logger,\n tenant,\n theme,\n nonce,\n locale,\n debug,\n client,\n form,\n telemetryKey,\n redirectUrl,\n autoFocus,\n validateOnBlur,\n restartOnError,\n errorTransformer,\n styleId,\n onScreenUpdate,\n dismissScreenErrorOnInput,\n outboundAppId,\n outboundAppScopes,\n popupOrigin,\n children,\n externalRequestId,\n themeOverride,\n },\n ref,\n ) => {\n const [innerRef, setInnerRef] = useState(null);\n\n useImperativeHandle(ref, () => innerRef);\n\n const {\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n sdk,\n } = React.useContext(Context);\n\n const handleSuccess = useCallback(\n async (e: CustomEvent) => {\n // In order to make sure all the after-hooks are running with the success response\n // we are generating a fake response with the success data and calling the http client after hook fn with it\n await sdk.httpClient.hooks.afterRequest(\n {} as any,\n new Response(JSON.stringify(e.detail)),\n );\n if (onSuccess) {\n onSuccess(e);\n }\n },\n [onSuccess],\n );\n\n useEffect(() => {\n const ele = innerRef;\n ele?.addEventListener('success', handleSuccess);\n if (onError) ele?.addEventListener('error', onError);\n if (onReady) ele?.addEventListener('ready', onReady);\n\n return () => {\n if (onError) ele?.removeEventListener('error', onError);\n if (onReady) ele?.removeEventListener('ready', onReady);\n\n ele?.removeEventListener('success', handleSuccess);\n };\n }, [innerRef, onError, handleSuccess]);\n\n // Success event\n useEffect(() => {\n const ele = innerRef;\n ele?.addEventListener('success', handleSuccess);\n return () => {\n ele?.removeEventListener('success', handleSuccess);\n };\n }, [innerRef, handleSuccess]);\n\n // Error event\n useEffect(() => {\n const ele = innerRef;\n if (onError) ele?.addEventListener('error', onError);\n\n return () => {\n if (onError) ele?.removeEventListener('error', onError);\n };\n }, [innerRef, onError]);\n\n // Ready event\n useEffect(() => {\n const ele = innerRef;\n if (onReady) ele?.addEventListener('ready', onReady);\n\n return () => {\n if (onReady) ele?.removeEventListener('error', onReady);\n };\n }, [innerRef, onReady]);\n\n return (\n /**\n * in order to avoid redundant remounting of the WC, we are wrapping it with a form element\n * this workaround is done in order to support webauthn passkeys\n * it can be removed once this issue will be solved\n * https://bugs.chromium.org/p/chromium/issues/detail?id=1404106#c2\n */\n <form>\n <Suspense fallback={null}>\n <DescopeWC\n projectId={projectId}\n flowId={flowId}\n baseUrl={baseUrl}\n baseStaticUrl={baseStaticUrl}\n baseCdnUrl={baseCdnUrl}\n ref={setInnerRef}\n telemetryKey={telemetryKey}\n redirectUrl={redirectUrl}\n autoFocus={autoFocus}\n styleId={styleId}\n validateOnBlur={validateOnBlur}\n restartOnError={restartOnError}\n keepLastAuthenticatedUserAfterLogout={\n keepLastAuthenticatedUserAfterLogout\n }\n tenant={tenant}\n externalRequestId={externalRequestId}\n customStorage={customStorage}\n themeOverride={themeOverride}\n {...{\n // attributes\n 'theme.attr': theme,\n 'nonce.attr': nonce,\n 'locale.attr': locale,\n 'form.attr': form,\n 'client.attr': client,\n 'debug.attr': debug,\n 'outbound-app-id.attr': outboundAppId,\n 'outbound-app-scopes.attr': outboundAppScopes,\n 'popup-origin.attr': popupOrigin,\n 'store-last-authenticated-user.attr': storeLastAuthenticatedUser,\n 'refreshCookieName.attr': refreshCookieName,\n 'dismiss-screen-error-on-input.attr': dismissScreenErrorOnInput,\n // props\n 'errorTransformer.prop': errorTransformer,\n 'logger.prop': logger,\n 'onScreenUpdate.prop': onScreenUpdate,\n 'customStorage.prop': customStorage,\n }}\n >\n {children}\n </DescopeWC>\n </Suspense>\n </form>\n );\n },\n);\n\nexport default Descope;\n"],"names":["DescopeWC","lazy","async","customElements","get","import","then","module","default","sdkConfigOverrides","baseHeaders","persistTokens","hooks","beforeRequest","getGlobalSdk","httpClient","_","withPropsMapping","React","forwardRef","_a","ref","externalRequestId","props","__rest","useMemo","key","value","Descope","flowId","onSuccess","onError","onReady","logger","tenant","theme","nonce","locale","debug","client","form","telemetryKey","redirectUrl","autoFocus","validateOnBlur","restartOnError","errorTransformer","styleId","onScreenUpdate","dismissScreenErrorOnInput","outboundAppId","outboundAppScopes","popupOrigin","children","themeOverride","innerRef","setInnerRef","useState","useImperativeHandle","projectId","baseUrl","baseStaticUrl","baseCdnUrl","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","customStorage","sdk","useContext","Context","handleSuccess","useCallback","e","afterRequest","Response","JSON","stringify","detail","useEffect","ele","addEventListener","removeEventListener","createElement","Suspense","fallback"],"mappings":"0SAiBA,MAAMA,EAAYC,EAAIA,MAACC,YAUnB,OAAAC,qBAAA,IAAAA,oBAAA,EAAAA,eAAgBC,IAAI,sBACbC,OAAO,0BAA0BC,MAAMC,GAAWA,EAAOC,WAErDC,mBAAqB,aAEhCC,EAAWA,YAIXC,eAAe,EACfC,MAAO,CACL,iBAAIC,GAIF,OAAOC,iBAAeC,WAAWH,MAAMC,aACxC,EACD,iBAAIA,CAAcG,GAGjB,IAIE,CACLR,QAASS,EAAgBT,QACvBU,EAAKV,QAACW,YACJ,CAACC,EAA6DC,SAA3D,sBAAuBC,GAAiBF,EAAKG,EAAKC,EAAAA,OAAAJ,EAApD,yBAMC,OAJAK,EAAAA,SAAQ,KAtCY,IAACC,EAAaC,EAAbD,EAuCC,kBAvCYC,EAuCML,GArC5CZ,cAAYgB,GAAOC,SAEZjB,EAAAA,YAAYgB,EAmC2C,GACvD,CAACJ,IAEGJ,oDAAYG,IAAKA,GAASE,GAAS,SAO9CK,EAAUV,EAAKV,QAACW,YACpB,EAEIU,SACAC,YACAC,UACAC,UACAC,SACAC,SACAC,QACAC,QACAC,SACAC,QACAC,SACAC,OACAC,eACAC,cACAC,YACAC,iBACAC,iBACAC,mBACAC,UACAC,iBACAC,4BACAC,gBACAC,oBACAC,cACAC,WACA/B,oBACAgC,iBAEFjC,KAEA,MAAOkC,EA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BAAoB,QAASjD,GAAQ,CACxD,GACA,CAACuB,EAAUvB,IASZd,UAAAgE,cAAA,OAAA,KACEhE,EAAAA,QAAAgE,cAACC,EAAAA,SAAQ,CAACC,SAAU,MAClBlE,EAAAV,QAAA0E,cAAClF,EAAS,CACR2D,UAAWA,EACX9B,OAAQA,EACR+B,QAASA,EACTC,cAAeA,EACfC,WAAYA,EACZzC,IAAKmC,EACLf,aAAcA,EACdC,YAAaA,EACbC,UAAWA,EACXI,QAASA,EACTH,eAAgBA,EAChBC,eAAgBA,EAChBmB,qCACEA,EAEF9B,OAAQA,EACRZ,kBAAmBA,EACnB4C,cAAeA,EACfZ,cAAeA,EAGb,aAAcnB,EACd,aAAcC,EACd,cAAeC,EACf,YAAaG,EACb,cAAeD,EACf,aAAcD,EACd,uBAAwBY,EACxB,2BAA4BC,EAC5B,oBAAqBC,EACrB,qCAAsCW,EACtC,yBAA0BE,EAC1B,qCAAsChB,EAEtC,wBAAyBH,EACzB,cAAeb,EACf,sBAAuBe,EACvB,qBAAsBkB,GAGvBb,IAIP"}
|
|
1
|
+
{"version":3,"file":"Descope.js","sources":["../../../src/components/Descope.tsx"],"sourcesContent":["/* eslint-disable react/prop-types */\nimport React, {\n lazy,\n Suspense,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react';\nimport { baseHeaders } from '../constants';\nimport Context from '../hooks/Context';\nimport { DescopeProps } from '../types';\nimport { getGlobalSdk } from '../sdk';\nimport withPropsMapping from './withPropsMapping';\n\n// web-component code uses browser API, but can be used in SSR apps, hence the lazy loading\nconst DescopeWC = lazy(async () => {\n const updateDynamicHeader = (key: string, value: string) => {\n if (value) {\n baseHeaders[key] = value;\n } else {\n delete baseHeaders[key];\n }\n };\n\n const WebComponent: any =\n customElements?.get('descope-wc') ||\n (await import('@descope/web-component').then((module) => module.default));\n\n WebComponent.sdkConfigOverrides = {\n // Overrides the web-component's base headers to indicate usage via the React SDK\n baseHeaders,\n // Disables token persistence within the web-component to delegate token management\n // to the global SDK hooks. This ensures token handling aligns with the SDK's configuration,\n // and web-component requests leverage the global SDK's beforeRequest hooks for consistency\n persistTokens: false,\n hooks: {\n get beforeRequest() {\n // Retrieves the beforeRequest hook from the global SDK, which is initialized\n // within the AuthProvider using the desired configuration. This approach ensures\n // the web-component utilizes the same beforeRequest hooks as the global SDK\n return getGlobalSdk().httpClient.hooks.beforeRequest;\n },\n set beforeRequest(_) {\n // The empty setter prevents runtime errors when attempts are made to assign a value to 'beforeRequest'.\n // JavaScript objects default to having both getters and setters\n },\n },\n };\n\n return {\n default: withPropsMapping(\n React.forwardRef<HTMLElement>(\n ({ 'external-request-id': externalRequestId, ...props }: any, ref) => {\n // update the dynamic headers with the external request ID if provided\n useMemo(() => {\n updateDynamicHeader('x-external-rid', externalRequestId);\n }, [externalRequestId]);\n\n return <descope-wc ref={ref} {...props} />;\n },\n ),\n ),\n };\n});\n\nconst Descope = React.forwardRef<HTMLElement, DescopeProps>(\n (\n {\n flowId,\n onSuccess,\n onError,\n onReady,\n logger,\n tenant,\n theme,\n nonce,\n locale,\n debug,\n client,\n form,\n telemetryKey,\n redirectUrl,\n autoFocus,\n validateOnBlur,\n restartOnError,\n errorTransformer,\n styleId,\n onScreenUpdate,\n dismissScreenErrorOnInput,\n outboundAppId,\n outboundAppScopes,\n popupOrigin,\n children,\n externalRequestId,\n themeOverride,\n },\n ref,\n ) => {\n const [innerRef, setInnerRef] = useState(null);\n\n useImperativeHandle(ref, () => innerRef);\n\n const {\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n sdk,\n } = React.useContext(Context);\n\n const handleSuccess = useCallback(\n async (e: CustomEvent) => {\n // In order to make sure all the after-hooks are running with the success response\n // we are generating a fake response with the success data and calling the http client after hook fn with it\n await sdk.httpClient.hooks.afterRequest(\n {} as any,\n new Response(JSON.stringify(e.detail)),\n );\n if (onSuccess) {\n onSuccess(e);\n }\n },\n [onSuccess],\n );\n\n useEffect(() => {\n const ele = innerRef;\n ele?.addEventListener('success', handleSuccess);\n if (onError) ele?.addEventListener('error', onError);\n if (onReady) ele?.addEventListener('ready', onReady);\n\n return () => {\n if (onError) ele?.removeEventListener('error', onError);\n if (onReady) ele?.removeEventListener('ready', onReady);\n\n ele?.removeEventListener('success', handleSuccess);\n };\n }, [innerRef, onError, handleSuccess]);\n\n // Success event\n useEffect(() => {\n const ele = innerRef;\n ele?.addEventListener('success', handleSuccess);\n return () => {\n ele?.removeEventListener('success', handleSuccess);\n };\n }, [innerRef, handleSuccess]);\n\n // Error event\n useEffect(() => {\n const ele = innerRef;\n if (onError) ele?.addEventListener('error', onError);\n\n return () => {\n if (onError) ele?.removeEventListener('error', onError);\n };\n }, [innerRef, onError]);\n\n // Ready event\n useEffect(() => {\n const ele = innerRef;\n if (onReady) ele?.addEventListener('ready', onReady);\n\n return () => {\n if (onReady) ele?.removeEventListener('error', onReady);\n };\n }, [innerRef, onReady]);\n\n return (\n /**\n * in order to avoid redundant remounting of the WC, we are wrapping it with a form element\n * this workaround is done in order to support webauthn passkeys\n * it can be removed once this issue will be solved\n * https://bugs.chromium.org/p/chromium/issues/detail?id=1404106#c2\n */\n\t<form>\n\t\t<Suspense fallback={null}>\n\t\t\t<DescopeWC\n projectId={projectId}\n flowId={flowId}\n baseUrl={baseUrl}\n baseStaticUrl={baseStaticUrl}\n baseCdnUrl={baseCdnUrl}\n ref={setInnerRef}\n telemetryKey={telemetryKey}\n redirectUrl={redirectUrl}\n autoFocus={autoFocus}\n styleId={styleId}\n validateOnBlur={validateOnBlur}\n restartOnError={restartOnError}\n keepLastAuthenticatedUserAfterLogout={\n keepLastAuthenticatedUserAfterLogout\n }\n tenant={tenant}\n externalRequestId={externalRequestId}\n customStorage={customStorage}\n themeOverride={themeOverride}\n {...{\n // attributes\n 'theme.attr': theme,\n 'nonce.attr': nonce,\n 'locale.attr': locale,\n 'form.attr': form,\n 'client.attr': client,\n 'debug.attr': debug,\n 'outbound-app-id.attr': outboundAppId,\n 'outbound-app-scopes.attr': outboundAppScopes,\n 'popup-origin.attr': popupOrigin,\n 'store-last-authenticated-user.attr': storeLastAuthenticatedUser,\n 'refreshCookieName.attr': refreshCookieName,\n 'dismiss-screen-error-on-input.attr': dismissScreenErrorOnInput,\n // props\n 'errorTransformer.prop': errorTransformer,\n 'logger.prop': logger,\n 'onScreenUpdate.prop': onScreenUpdate,\n 'customStorage.prop': customStorage,\n }}\n >\n\t\t\t\t{children}\n\t\t\t</DescopeWC>\n\t\t</Suspense>\n\t</form>\n );\n },\n);\n\nexport default Descope;\n"],"names":["DescopeWC","lazy","async","customElements","get","import","then","module","default","sdkConfigOverrides","baseHeaders","persistTokens","hooks","beforeRequest","getGlobalSdk","httpClient","_","withPropsMapping","React","forwardRef","_a","ref","externalRequestId","props","__rest","useMemo","key","value","Descope","flowId","onSuccess","onError","onReady","logger","tenant","theme","nonce","locale","debug","client","form","telemetryKey","redirectUrl","autoFocus","validateOnBlur","restartOnError","errorTransformer","styleId","onScreenUpdate","dismissScreenErrorOnInput","outboundAppId","outboundAppScopes","popupOrigin","children","themeOverride","innerRef","setInnerRef","useState","useImperativeHandle","projectId","baseUrl","baseStaticUrl","baseCdnUrl","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","customStorage","sdk","useContext","Context","handleSuccess","useCallback","e","afterRequest","Response","JSON","stringify","detail","useEffect","ele","addEventListener","removeEventListener","createElement","Suspense","fallback"],"mappings":"0SAiBA,MAAMA,EAAYC,EAAIA,MAACC,YAUnB,OAAAC,qBAAA,IAAAA,oBAAA,EAAAA,eAAgBC,IAAI,sBACbC,OAAO,0BAA0BC,MAAMC,GAAWA,EAAOC,WAErDC,mBAAqB,aAEhCC,EAAWA,YAIXC,eAAe,EACfC,MAAO,CACL,iBAAIC,GAIF,OAAOC,iBAAeC,WAAWH,MAAMC,aACxC,EACD,iBAAIA,CAAcG,GAGjB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js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e="undefined"!=typeof window;exports.IS_BROWSER=e,exports.baseHeaders={"x-descope-sdk-name":"react","x-descope-sdk-version":"3.0
|
|
1
|
+
"use strict";const e="undefined"!=typeof window;exports.IS_BROWSER=e,exports.baseHeaders={"x-descope-sdk-name":"react","x-descope-sdk-version":"3.1.0"};
|
|
2
2
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccessKeyManagement.js","sources":["../../../src/components/AccessKeyManagement.tsx"],"sourcesContent":["import React, {\n lazy,\n Suspense,\n useImperativeHandle,\n useState,\n useEffect,\n} from 'react';\nimport Context from '../hooks/Context';\nimport { AccessKeyManagementProps } from '../types';\nimport withPropsMapping from './withPropsMapping';\n\n// web-component code uses browser API, but can be used in SSR apps, hence the lazy loading\nconst AccessKeyManagementWC = lazy(async () => {\n await import('@descope/access-key-management-widget');\n\n return {\n default: withPropsMapping(\n React.forwardRef<HTMLElement>((props, ref) => (\n
|
|
1
|
+
{"version":3,"file":"AccessKeyManagement.js","sources":["../../../src/components/AccessKeyManagement.tsx"],"sourcesContent":["import React, {\n lazy,\n Suspense,\n useImperativeHandle,\n useState,\n useEffect,\n} from 'react';\nimport Context from '../hooks/Context';\nimport { AccessKeyManagementProps } from '../types';\nimport withPropsMapping from './withPropsMapping';\n\n// web-component code uses browser API, but can be used in SSR apps, hence the lazy loading\nconst AccessKeyManagementWC = lazy(async () => {\n await import('@descope/access-key-management-widget');\n\n return {\n default: withPropsMapping(\n React.forwardRef<HTMLElement>((props, ref) => (\n\t<descope-access-key-management-widget ref={ref} {...props} />\n )),\n ),\n };\n});\n\nconst AccessKeyManagement = React.forwardRef<\n HTMLElement,\n AccessKeyManagementProps\n>(\n (\n { logger, tenant, theme, locale, debug, widgetId, styleId, onReady },\n ref,\n ) => {\n const [innerRef, setInnerRef] = useState(null);\n\n useImperativeHandle(ref, () => innerRef);\n\n const { projectId, baseUrl, baseStaticUrl, baseCdnUrl, refreshCookieName } =\n React.useContext(Context);\n\n useEffect(() => {\n const ele = innerRef;\n if (onReady) ele?.addEventListener('ready', onReady);\n\n return () => {\n if (onReady) ele?.removeEventListener('ready', onReady);\n };\n }, [innerRef, onReady]);\n\n return (\n\t<Suspense fallback={null}>\n\t\t<AccessKeyManagementWC\n ref={setInnerRef}\n projectId={projectId}\n widgetId={widgetId}\n tenant={tenant}\n baseUrl={baseUrl}\n baseStaticUrl={baseStaticUrl}\n baseCdnUrl={baseCdnUrl}\n {...{\n // attributes\n 'theme.attr': theme,\n 'locale.attr': locale,\n 'debug.attr': debug,\n 'styleId.attr': styleId,\n 'refreshCookieName.attr': refreshCookieName,\n // props\n 'logger.prop': logger,\n }}\n />\n\t</Suspense>\n );\n },\n);\n\nexport default AccessKeyManagement;\n"],"names":["AccessKeyManagementWC","lazy","async","import","default","withPropsMapping","React","forwardRef","props","ref","createElement","Object","assign","AccessKeyManagement","logger","tenant","theme","locale","debug","widgetId","styleId","onReady","innerRef","setInnerRef","useState","useImperativeHandle","projectId","baseUrl","baseStaticUrl","baseCdnUrl","refreshCookieName","useContext","Context","useEffect","ele","addEventListener","removeEventListener","Suspense","fallback"],"mappings":"kLAYA,MAAMA,EAAwBC,GAAKC,gBAC3BC,OAAO,yCAEN,CACLC,QAASC,EACPC,EAAMC,YAAwB,CAACC,EAAOC,IAC3CH,EAAsCI,cAAA,uCAAAC,OAAAC,OAAA,CAAAH,IAAKA,GAASD,WAM/CK,EAAsBP,EAAMC,YAIhC,EACIO,SAAQC,SAAQC,QAAOC,SAAQC,QAAOC,WAAUC,UAASC,WAC3DZ,KAEA,MAAOa,EAAUC,GAAeC,EAAS,MAEzCC,EAAoBhB,GAAK,IAAMa,IAE/B,MAAMI,UAAEA,EAASC,QAAEA,EAAOC,cAAEA,EAAaC,WAAEA,EAAUC,kBAAEA,GACrDxB,EAAMyB,WAAWC,GAWnB,OATAC,GAAU,KACR,MAAMC,EAAMZ,EAGZ,OAFID,IAASa,SAAAA,EAAKC,iBAAiB,QAASd,IAErC,KACDA,IAASa,SAAAA,EAAKE,oBAAoB,QAASf,GAAQ,CACxD,GACA,CAACC,EAAUD,IAGjBf,EAACI,cAAA2B,EAAS,CAAAC,SAAU,MACnBhC,EAAAI,cAACV,EAAqB,CACdS,IAAKc,EACLG,UAAWA,EACXP,SAAUA,EACVJ,OAAQA,EACRY,QAASA,EACTC,cAAeA,EACfC,WAAYA,EAGV,aAAcb,EACd,cAAeC,EACf,aAAcC,EACd,eAAgBE,EAChB,yBAA0BU,EAE1B,cAAehB,IAIrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Descope.js","sources":["../../../src/components/Descope.tsx"],"sourcesContent":["/* eslint-disable react/prop-types */\nimport React, {\n lazy,\n Suspense,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react';\nimport { baseHeaders } from '../constants';\nimport Context from '../hooks/Context';\nimport { DescopeProps } from '../types';\nimport { getGlobalSdk } from '../sdk';\nimport withPropsMapping from './withPropsMapping';\n\n// web-component code uses browser API, but can be used in SSR apps, hence the lazy loading\nconst DescopeWC = lazy(async () => {\n const updateDynamicHeader = (key: string, value: string) => {\n if (value) {\n baseHeaders[key] = value;\n } else {\n delete baseHeaders[key];\n }\n };\n\n const WebComponent: any =\n customElements?.get('descope-wc') ||\n (await import('@descope/web-component').then((module) => module.default));\n\n WebComponent.sdkConfigOverrides = {\n // Overrides the web-component's base headers to indicate usage via the React SDK\n baseHeaders,\n // Disables token persistence within the web-component to delegate token management\n // to the global SDK hooks. This ensures token handling aligns with the SDK's configuration,\n // and web-component requests leverage the global SDK's beforeRequest hooks for consistency\n persistTokens: false,\n hooks: {\n get beforeRequest() {\n // Retrieves the beforeRequest hook from the global SDK, which is initialized\n // within the AuthProvider using the desired configuration. This approach ensures\n // the web-component utilizes the same beforeRequest hooks as the global SDK\n return getGlobalSdk().httpClient.hooks.beforeRequest;\n },\n set beforeRequest(_) {\n // The empty setter prevents runtime errors when attempts are made to assign a value to 'beforeRequest'.\n // JavaScript objects default to having both getters and setters\n },\n },\n };\n\n return {\n default: withPropsMapping(\n React.forwardRef<HTMLElement>(\n ({ 'external-request-id': externalRequestId, ...props }: any, ref) => {\n // update the dynamic headers with the external request ID if provided\n useMemo(() => {\n updateDynamicHeader('x-external-rid', externalRequestId);\n }, [externalRequestId]);\n\n return <descope-wc ref={ref} {...props} />;\n },\n ),\n ),\n };\n});\n\nconst Descope = React.forwardRef<HTMLElement, DescopeProps>(\n (\n {\n flowId,\n onSuccess,\n onError,\n onReady,\n logger,\n tenant,\n theme,\n nonce,\n locale,\n debug,\n client,\n form,\n telemetryKey,\n redirectUrl,\n autoFocus,\n validateOnBlur,\n restartOnError,\n errorTransformer,\n styleId,\n onScreenUpdate,\n dismissScreenErrorOnInput,\n outboundAppId,\n outboundAppScopes,\n popupOrigin,\n children,\n externalRequestId,\n themeOverride,\n },\n ref,\n ) => {\n const [innerRef, setInnerRef] = useState(null);\n\n useImperativeHandle(ref, () => innerRef);\n\n const {\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n sdk,\n } = React.useContext(Context);\n\n const handleSuccess = useCallback(\n async (e: CustomEvent) => {\n // In order to make sure all the after-hooks are running with the success response\n // we are generating a fake response with the success data and calling the http client after hook fn with it\n await sdk.httpClient.hooks.afterRequest(\n {} as any,\n new Response(JSON.stringify(e.detail)),\n );\n if (onSuccess) {\n onSuccess(e);\n }\n },\n [onSuccess],\n );\n\n useEffect(() => {\n const ele = innerRef;\n ele?.addEventListener('success', handleSuccess);\n if (onError) ele?.addEventListener('error', onError);\n if (onReady) ele?.addEventListener('ready', onReady);\n\n return () => {\n if (onError) ele?.removeEventListener('error', onError);\n if (onReady) ele?.removeEventListener('ready', onReady);\n\n ele?.removeEventListener('success', handleSuccess);\n };\n }, [innerRef, onError, handleSuccess]);\n\n // Success event\n useEffect(() => {\n const ele = innerRef;\n ele?.addEventListener('success', handleSuccess);\n return () => {\n ele?.removeEventListener('success', handleSuccess);\n };\n }, [innerRef, handleSuccess]);\n\n // Error event\n useEffect(() => {\n const ele = innerRef;\n if (onError) ele?.addEventListener('error', onError);\n\n return () => {\n if (onError) ele?.removeEventListener('error', onError);\n };\n }, [innerRef, onError]);\n\n // Ready event\n useEffect(() => {\n const ele = innerRef;\n if (onReady) ele?.addEventListener('ready', onReady);\n\n return () => {\n if (onReady) ele?.removeEventListener('error', onReady);\n };\n }, [innerRef, onReady]);\n\n return (\n /**\n * in order to avoid redundant remounting of the WC, we are wrapping it with a form element\n * this workaround is done in order to support webauthn passkeys\n * it can be removed once this issue will be solved\n * https://bugs.chromium.org/p/chromium/issues/detail?id=1404106#c2\n */\n <form>\n <Suspense fallback={null}>\n <DescopeWC\n projectId={projectId}\n flowId={flowId}\n baseUrl={baseUrl}\n baseStaticUrl={baseStaticUrl}\n baseCdnUrl={baseCdnUrl}\n ref={setInnerRef}\n telemetryKey={telemetryKey}\n redirectUrl={redirectUrl}\n autoFocus={autoFocus}\n styleId={styleId}\n validateOnBlur={validateOnBlur}\n restartOnError={restartOnError}\n keepLastAuthenticatedUserAfterLogout={\n keepLastAuthenticatedUserAfterLogout\n }\n tenant={tenant}\n externalRequestId={externalRequestId}\n customStorage={customStorage}\n themeOverride={themeOverride}\n {...{\n // attributes\n 'theme.attr': theme,\n 'nonce.attr': nonce,\n 'locale.attr': locale,\n 'form.attr': form,\n 'client.attr': client,\n 'debug.attr': debug,\n 'outbound-app-id.attr': outboundAppId,\n 'outbound-app-scopes.attr': outboundAppScopes,\n 'popup-origin.attr': popupOrigin,\n 'store-last-authenticated-user.attr': storeLastAuthenticatedUser,\n 'refreshCookieName.attr': refreshCookieName,\n 'dismiss-screen-error-on-input.attr': dismissScreenErrorOnInput,\n // props\n 'errorTransformer.prop': errorTransformer,\n 'logger.prop': logger,\n 'onScreenUpdate.prop': onScreenUpdate,\n 'customStorage.prop': customStorage,\n }}\n >\n {children}\n </DescopeWC>\n </Suspense>\n </form>\n );\n },\n);\n\nexport default Descope;\n"],"names":["DescopeWC","lazy","async","customElements","get","import","then","module","default","sdkConfigOverrides","baseHeaders","persistTokens","hooks","beforeRequest","getGlobalSdk","httpClient","_","withPropsMapping","React","forwardRef","_a","ref","externalRequestId","props","__rest","useMemo","key","value","Descope","flowId","onSuccess","onError","onReady","logger","tenant","theme","nonce","locale","debug","client","form","telemetryKey","redirectUrl","autoFocus","validateOnBlur","restartOnError","errorTransformer","styleId","onScreenUpdate","dismissScreenErrorOnInput","outboundAppId","outboundAppScopes","popupOrigin","children","themeOverride","innerRef","setInnerRef","useState","useImperativeHandle","projectId","baseUrl","baseStaticUrl","baseCdnUrl","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","customStorage","sdk","useContext","Context","handleSuccess","useCallback","e","afterRequest","Response","JSON","stringify","detail","useEffect","ele","addEventListener","removeEventListener","createElement","Suspense","fallback"],"mappings":"sUAiBA,MAAMA,EAAYC,GAAKC,YAUnB,OAAAC,qBAAA,IAAAA,oBAAA,EAAAA,eAAgBC,IAAI,sBACbC,OAAO,0BAA0BC,MAAMC,GAAWA,EAAOC,WAErDC,mBAAqB,CAEhCC,cAIAC,eAAe,EACfC,MAAO,CACL,iBAAIC,GAIF,OAAOC,IAAeC,WAAWH,MAAMC,aACxC,EACD,iBAAIA,CAAcG,GAGjB,IAIE,CACLR,QAASS,EACPC,EAAMC,YACJ,CAACC,EAA6DC,SAA3D,sBAAuBC,GAAiBF,EAAKG,EAAKC,EAAAJ,EAApD,yBAMC,OAJAK,GAAQ,KAtCY,IAACC,EAAaC,EAAbD,EAuCC,kBAvCYC,EAuCML,GArC5CZ,EAAYgB,GAAOC,SAEZjB,EAAYgB,EAmC2C,GACvD,CAACJ,IAEGJ,4CAAYG,IAAKA,GAASE,GAAS,SAO9CK,EAAUV,EAAMC,YACpB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D,GACA,CAACwB,EAAUxB,IAGd+C,GAAU,KACR,MAAMC,EAAMxB,EAGZ,OAFIvB,IAAS+C,SAAAA,EAAKC,iBAAiB,QAAShD,IAErC,KACDA,IAAS+C,SAAAA,EAAKE,oBAAoB,QAASjD,GAAQ,CACxD,GACA,CAACuB,EAAUvB,IASZd,EAAAgE,cAAA,OAAA,KACEhE,EAAAgE,cAACC,EAAQ,CAACC,SAAU,MAClBlE,EAAAgE,cAAClF,EAAS,CACR2D,UAAWA,EACX9B,OAAQA,EACR+B,QAASA,EACTC,cAAeA,EACfC,WAAYA,EACZzC,IAAKmC,EACLf,aAAcA,EACdC,YAAaA,EACbC,UAAWA,EACXI,QAASA,EACTH,eAAgBA,EAChBC,eAAgBA,EAChBmB,qCACEA,EAEF9B,OAAQA,EACRZ,kBAAmBA,EACnB4C,cAAeA,EACfZ,cAAeA,EAGb,aAAcnB,EACd,aAAcC,EACd,cAAeC,EACf,YAAaG,EACb,cAAeD,EACf,aAAcD,EACd,uBAAwBY,EACxB,2BAA4BC,EAC5B,oBAAqBC,EACrB,qCAAsCW,EACtC,yBAA0BE,EAC1B,qCAAsChB,EAEtC,wBAAyBH,EACzB,cAAeb,EACf,sBAAuBe,EACvB,qBAAsBkB,GAGvBb,IAIP"}
|
|
1
|
+
{"version":3,"file":"Descope.js","sources":["../../../src/components/Descope.tsx"],"sourcesContent":["/* eslint-disable react/prop-types */\nimport React, {\n lazy,\n Suspense,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useState,\n} from 'react';\nimport { baseHeaders } from '../constants';\nimport Context from '../hooks/Context';\nimport { DescopeProps } from '../types';\nimport { getGlobalSdk } from '../sdk';\nimport withPropsMapping from './withPropsMapping';\n\n// web-component code uses browser API, but can be used in SSR apps, hence the lazy loading\nconst DescopeWC = lazy(async () => {\n const updateDynamicHeader = (key: string, value: string) => {\n if (value) {\n baseHeaders[key] = value;\n } else {\n delete baseHeaders[key];\n }\n };\n\n const WebComponent: any =\n customElements?.get('descope-wc') ||\n (await import('@descope/web-component').then((module) => module.default));\n\n WebComponent.sdkConfigOverrides = {\n // Overrides the web-component's base headers to indicate usage via the React SDK\n baseHeaders,\n // Disables token persistence within the web-component to delegate token management\n // to the global SDK hooks. This ensures token handling aligns with the SDK's configuration,\n // and web-component requests leverage the global SDK's beforeRequest hooks for consistency\n persistTokens: false,\n hooks: {\n get beforeRequest() {\n // Retrieves the beforeRequest hook from the global SDK, which is initialized\n // within the AuthProvider using the desired configuration. This approach ensures\n // the web-component utilizes the same beforeRequest hooks as the global SDK\n return getGlobalSdk().httpClient.hooks.beforeRequest;\n },\n set beforeRequest(_) {\n // The empty setter prevents runtime errors when attempts are made to assign a value to 'beforeRequest'.\n // JavaScript objects default to having both getters and setters\n },\n },\n };\n\n return {\n default: withPropsMapping(\n React.forwardRef<HTMLElement>(\n ({ 'external-request-id': externalRequestId, ...props }: any, ref) => {\n // update the dynamic headers with the external request ID if provided\n useMemo(() => {\n updateDynamicHeader('x-external-rid', externalRequestId);\n }, [externalRequestId]);\n\n return <descope-wc ref={ref} {...props} />;\n },\n ),\n ),\n };\n});\n\nconst Descope = React.forwardRef<HTMLElement, DescopeProps>(\n (\n {\n flowId,\n onSuccess,\n onError,\n onReady,\n logger,\n tenant,\n theme,\n nonce,\n locale,\n debug,\n client,\n form,\n telemetryKey,\n redirectUrl,\n autoFocus,\n validateOnBlur,\n restartOnError,\n errorTransformer,\n styleId,\n onScreenUpdate,\n dismissScreenErrorOnInput,\n outboundAppId,\n outboundAppScopes,\n popupOrigin,\n children,\n externalRequestId,\n themeOverride,\n },\n ref,\n ) => {\n const [innerRef, setInnerRef] = useState(null);\n\n useImperativeHandle(ref, () => innerRef);\n\n const {\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n sdk,\n } = React.useContext(Context);\n\n const handleSuccess = useCallback(\n async (e: CustomEvent) => {\n // In order to make sure all the after-hooks are running with the success response\n // we are generating a fake response with the success data and calling the http client after hook fn with it\n await sdk.httpClient.hooks.afterRequest(\n {} as any,\n new Response(JSON.stringify(e.detail)),\n );\n if (onSuccess) {\n onSuccess(e);\n }\n },\n [onSuccess],\n );\n\n useEffect(() => {\n const ele = innerRef;\n ele?.addEventListener('success', handleSuccess);\n if (onError) ele?.addEventListener('error', onError);\n if (onReady) ele?.addEventListener('ready', onReady);\n\n return () => {\n if (onError) ele?.removeEventListener('error', onError);\n if (onReady) ele?.removeEventListener('ready', onReady);\n\n ele?.removeEventListener('success', handleSuccess);\n };\n }, [innerRef, onError, handleSuccess]);\n\n // Success event\n useEffect(() => {\n const ele = innerRef;\n ele?.addEventListener('success', handleSuccess);\n return () => {\n ele?.removeEventListener('success', handleSuccess);\n };\n }, [innerRef, handleSuccess]);\n\n // Error event\n useEffect(() => {\n const ele = innerRef;\n if (onError) ele?.addEventListener('error', onError);\n\n return () => {\n if (onError) ele?.removeEventListener('error', onError);\n };\n }, [innerRef, onError]);\n\n // Ready event\n useEffect(() => {\n const ele = innerRef;\n if (onReady) ele?.addEventListener('ready', onReady);\n\n return () => {\n if (onReady) ele?.removeEventListener('error', onReady);\n };\n }, [innerRef, onReady]);\n\n return (\n /**\n * in order to avoid redundant remounting of the WC, we are wrapping it with a form element\n * this workaround is done in order to support webauthn passkeys\n * it can be removed once this issue will be solved\n * https://bugs.chromium.org/p/chromium/issues/detail?id=1404106#c2\n */\n\t<form>\n\t\t<Suspense fallback={null}>\n\t\t\t<DescopeWC\n projectId={projectId}\n flowId={flowId}\n baseUrl={baseUrl}\n baseStaticUrl={baseStaticUrl}\n baseCdnUrl={baseCdnUrl}\n ref={setInnerRef}\n telemetryKey={telemetryKey}\n redirectUrl={redirectUrl}\n autoFocus={autoFocus}\n styleId={styleId}\n validateOnBlur={validateOnBlur}\n restartOnError={restartOnError}\n keepLastAuthenticatedUserAfterLogout={\n keepLastAuthenticatedUserAfterLogout\n }\n tenant={tenant}\n externalRequestId={externalRequestId}\n customStorage={customStorage}\n themeOverride={themeOverride}\n {...{\n // attributes\n 'theme.attr': theme,\n 'nonce.attr': nonce,\n 'locale.attr': locale,\n 'form.attr': form,\n 'client.attr': client,\n 'debug.attr': debug,\n 'outbound-app-id.attr': outboundAppId,\n 'outbound-app-scopes.attr': outboundAppScopes,\n 'popup-origin.attr': popupOrigin,\n 'store-last-authenticated-user.attr': storeLastAuthenticatedUser,\n 'refreshCookieName.attr': refreshCookieName,\n 'dismiss-screen-error-on-input.attr': dismissScreenErrorOnInput,\n // props\n 'errorTransformer.prop': errorTransformer,\n 'logger.prop': logger,\n 'onScreenUpdate.prop': onScreenUpdate,\n 'customStorage.prop': customStorage,\n }}\n >\n\t\t\t\t{children}\n\t\t\t</DescopeWC>\n\t\t</Suspense>\n\t</form>\n );\n },\n);\n\nexport default Descope;\n"],"names":["DescopeWC","lazy","async","customElements","get","import","then","module","default","sdkConfigOverrides","baseHeaders","persistTokens","hooks","beforeRequest","getGlobalSdk","httpClient","_","withPropsMapping","React","forwardRef","_a","ref","externalRequestId","props","__rest","useMemo","key","value","Descope","flowId","onSuccess","onError","onReady","logger","tenant","theme","nonce","locale","debug","client","form","telemetryKey","redirectUrl","autoFocus","validateOnBlur","restartOnError","errorTransformer","styleId","onScreenUpdate","dismissScreenErrorOnInput","outboundAppId","outboundAppScopes","popupOrigin","children","themeOverride","innerRef","setInnerRef","useState","useImperativeHandle","projectId","baseUrl","baseStaticUrl","baseCdnUrl","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","customStorage","sdk","useContext","Context","handleSuccess","useCallback","e","afterRequest","Response","JSON","stringify","detail","useEffect","ele","addEventListener","removeEventListener","createElement","Suspense","fallback"],"mappings":"sUAiBA,MAAMA,EAAYC,GAAKC,YAUnB,OAAAC,qBAAA,IAAAA,oBAAA,EAAAA,eAAgBC,IAAI,sBACbC,OAAO,0BAA0BC,MAAMC,GAAWA,EAAOC,WAErDC,mBAAqB,CA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|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"3.0
|
|
1
|
+
const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"3.1.0"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
|
|
2
2
|
//# sourceMappingURL=constants.js.map
|