@descope/react-sdk 2.12.6 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -444,6 +444,28 @@ const AppRoot = () => {
444
444
 
445
445
  Descope stores the last user information in local storage. If you wish to disable this feature, you can pass `storeLastAuthenticatedUser={false}` to the `AuthProvider` component. Please note that some features related to the last authenticated user may not function as expected if this behavior is disabled. Local storage is being cleared when the user logs out, if you want the avoid clearing the local storage, you can pass `keepLastAuthenticatedUserAfterLogout={true}` to the `AuthProvider` component.
446
446
 
447
+ ### Seamless Session Migration
448
+
449
+ If you are migrating from an external authentication provider to Descope, you can use the `getExternalToken` prop in the `AuthProvider` component. This function should return a valid token from the external provider. The SDK will then use this token to authenticate the user with Descope.
450
+
451
+ ```js
452
+ import { AuthProvider } from '@descope/react-sdk';
453
+
454
+ const AppRoot = () => {
455
+ return (
456
+ <AuthProvider
457
+ projectId="my-project-id"
458
+ getExternalToken={async () => {
459
+ // Bring token from external provider (e.g. get access token from another auth provider)
460
+ return 'my-external-token';
461
+ }}
462
+ >
463
+ <App />
464
+ </AuthProvider>
465
+ );
466
+ };
467
+ ```
468
+
447
469
  ### Widgets
448
470
 
449
471
  Widgets are components that allow you to expose management features for tenant-based implementation. In certain scenarios, your customers may require the capability to perform managerial actions independently, alleviating the necessity to contact you. Widgets serve as a feature enabling you to delegate these capabilities to your customers in a modular manner.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../hooks/Context.js"),s=require("../../utils.js"),r=require("./useSdk.js");function i(e){return e&&e.__esModule?e:{default:e}}var n=i(e);exports.default=({projectId:i,baseUrl:o="",baseStaticUrl:a="",sessionTokenViaCookie:u=!1,persistTokens:c=!0,oidcConfig:d,storeLastAuthenticatedUser:f=!0,keepLastAuthenticatedUserAfterLogout:h=!1,refreshCookieName:l="",children:k})=>{const[U,S]=e.useState(),[C,L]=e.useState(),[g,A]=e.useState(!1),[p,b]=e.useState(!1),[j,m]=e.useState(!1),[v,I]=e.useState(!!d),T=e.useRef(!1),q=r.default({projectId:i,baseUrl:o,persistTokens:c,sessionTokenViaCookie:u,oidcConfig:d,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:h,refreshCookieName:l});e.useEffect((()=>{if(q){const e=q.onSessionTokenChange(L),t=q.onUserChange(S),s=q.onIsAuthenticatedChange(A);return()=>{e(),t(),s()}}}),[q]);const N=e.useRef(!1),V=e.useRef(!1);e.useEffect((()=>{q&&d&&!T.current&&(T.current=!0,q.oidc.finishLoginIfNeed().finally((()=>{I(!1),N.current=!0})))}),[]);const _=e.useCallback((()=>{N.current||(N.current=!0,m(!0),s.withValidation(null==q?void 0:q.refresh)().then((()=>{m(!1)})))}),[q]),x=e.useCallback((()=>{V.current||(V.current=!0,b(!0),s.withValidation(q.me)().then((()=>{b(!1)})))}),[q]),E=e.useMemo((()=>({fetchUser:x,user:U,isUserLoading:p,isUserFetched:V.current,fetchSession:_,session:C,isAuthenticated:g,isSessionLoading:j,isOidcLoading:v,isSessionFetched:N.current,projectId:i,baseUrl:o,baseStaticUrl:a,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:h,refreshCookieName:l,setUser:S,setSession:L,setIsAuthenticated:A,sdk:q})),[x,U,p,V.current,_,C,g,j,v,N.current,i,o,a,h,l,S,L,A,q]);return n.default.createElement(t.default.Provider,{value:E},k)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../hooks/Context.js"),s=require("../../utils.js"),r=require("./useSdk.js");function n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);exports.default=({projectId:n,baseUrl:i="",baseStaticUrl:a="",sessionTokenViaCookie:u=!1,persistTokens:c=!0,oidcConfig:d,storeLastAuthenticatedUser:f=!0,keepLastAuthenticatedUserAfterLogout:l=!1,refreshCookieName:h="",getExternalToken:k,children:U})=>{const[g,S]=e.useState(),[C,L]=e.useState(),[A,p]=e.useState(!1),[b,j]=e.useState(!1),[T,m]=e.useState(!1),[v,I]=e.useState(!!d),x=e.useRef(!1),E=r.default({projectId:n,baseUrl:i,persistTokens:c,sessionTokenViaCookie:u,oidcConfig:d,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:l,refreshCookieName:h,getExternalToken:k});e.useEffect((()=>{if(E){const e=E.onSessionTokenChange(L),t=E.onUserChange(S),s=E.onIsAuthenticatedChange(p);return()=>{e(),t(),s()}}}),[E]);const q=e.useRef(!1),N=e.useRef(!1);e.useEffect((()=>{E&&d&&!x.current&&(x.current=!0,E.oidc.finishLoginIfNeed().finally((()=>{I(!1),q.current=!0})))}),[]);const V=e.useCallback((()=>{q.current||(q.current=!0,m(!0),s.withValidation(null==E?void 0:E.refresh)().then((()=>{m(!1)})))}),[E]),_=e.useCallback((()=>{N.current||(N.current=!0,j(!0),s.withValidation(E.me)().then((()=>{j(!1)})))}),[E]),M=e.useMemo((()=>({fetchUser:_,user:g,isUserLoading:b,isUserFetched:N.current,fetchSession:V,session:C,isAuthenticated:A,isSessionLoading:T,isOidcLoading:v,isSessionFetched:q.current,projectId:n,baseUrl:i,baseStaticUrl:a,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:l,refreshCookieName:h,setUser:S,setSession:L,setIsAuthenticated:p,sdk:E})),[_,g,b,N.current,V,C,A,T,v,q.current,n,i,a,l,h,S,L,p,E]);return o.default.createElement(t.default.Provider,{value:M},U)};
2
2
  //# sourceMappingURL=AuthProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ninterface IAuthProviderProps {\n projectId: string;\n baseUrl?: string;\n // allows to override the base URL that is used to fetch static files\n baseStaticUrl?: string;\n // If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // If true, last authenticated user will be stored on local storage and can accessed with getUser function\n storeLastAuthenticatedUser?: boolean;\n // If true, last authenticated user will not be removed after logout\n keepLastAuthenticatedUserAfterLogout?: boolean;\n // Use this option if the authentication is done via cookie, and configured with a different name\n // Currently, this is done using Descope Flows\n refreshCookieName?: string;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n sessionTokenViaCookie = false,\n persistTokens = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [isAuthenticated, setIsAuthenticated] = useState(false);\n\n const [isUserLoading, setIsUserLoading] = useState(false);\n const [isSessionLoading, setIsSessionLoading] = useState(false);\n\n // if oidc config is enabled, we attempt to finish the login, so we start as loading\n const [isOidcLoading, setIsOidcLoading] = useState(!!oidcConfig);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n sessionTokenViaCookie,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n });\n\n useEffect(() => {\n if (sdk) {\n const unsubscribeSessionToken = sdk.onSessionTokenChange(setSession);\n const unsubscribeUser = sdk.onUserChange(setUser);\n const unsubscribeIsAuthenticated =\n sdk.onIsAuthenticatedChange(setIsAuthenticated);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetched = useRef(false);\n const isUserFetched = useRef(false);\n\n // if oidc config is enabled, and we have oidc params in the url\n // we will finish the login (this should run only once)\n useEffect(() => {\n if (sdk && oidcConfig && !isOidcFinishedLogin.current) {\n isOidcFinishedLogin.current = true;\n sdk.oidc.finishLoginIfNeed().finally(() => {\n setIsOidcLoading(false);\n // We want that the session will fetched only once\n isSessionFetched.current = true;\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // We want that the session will fetched only once\n if (isSessionFetched.current) return;\n isSessionFetched.current = true;\n\n setIsSessionLoading(true);\n withValidation(sdk?.refresh)().then(() => {\n setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n setUser,\n setSession,\n setIsAuthenticated,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n setUser,\n setSession,\n setIsAuthenticated,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["projectId","baseUrl","baseStaticUrl","sessionTokenViaCookie","persistTokens","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","children","user","setUser","useState","session","setSession","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","withValidation","refresh","then","fetchUser","me","value","useMemo","React","default","createElement","Context","Provider"],"mappings":"kQAuC6C,EAC3CA,YACAC,UAAU,GACVC,gBAAgB,GAChBC,yBAAwB,EACxBC,iBAAgB,EAChBC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,eAEA,MAAOC,EAAMC,GAAWC,EAAQA,YACzBC,EAASC,GAAcF,EAAQA,YAC/BG,EAAiBC,GAAsBJ,EAAQA,UAAC,IAEhDK,EAAeC,GAAoBN,EAAQA,UAAC,IAC5CO,EAAkBC,GAAuBR,EAAQA,UAAC,IAGlDS,EAAeC,GAAoBV,EAAAA,WAAWP,GAC/CkB,EAAsBC,UAAO,GAE7BC,EAAMC,EAAAA,QAAO,CACjB1B,YACAC,UACAG,gBACAD,wBACAE,aACAC,6BACAC,uCACAC,sBAGFmB,EAAAA,WAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBf,GACnDgB,EAAkBL,EAAIM,aAAapB,GACnCqB,EACJP,EAAIQ,wBAAwBjB,GAE9B,MAAO,KACLY,IACAE,IACAE,GAA4B,CAE/B,CACe,GACf,CAACP,IAEJ,MAAMS,EAAmBV,UAAO,GAC1BW,EAAgBX,UAAO,GAI7BG,EAAAA,WAAU,KACJF,GAAOpB,IAAekB,EAAoBa,UAC5Cb,EAAoBa,SAAU,EAC9BX,EAAIY,KAAKC,oBAAoBC,SAAQ,KACnCjB,GAAiB,GAEjBY,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,EAAAA,aAAY,KAE3BP,EAAiBE,UACrBF,EAAiBE,SAAU,EAE3BhB,GAAoB,GACpBsB,EAAAA,eAAejB,eAAAA,EAAKkB,QAApBD,GAA+BE,MAAK,KAClCxB,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEoB,EAAYJ,EAAAA,aAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBlB,GAAiB,GACjBwB,EAAAA,eAAejB,EAAIqB,GAAnBJ,GAAyBE,MAAK,KAC5B1B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEEsB,EAAQC,EAAAA,SACZ,KAAO,CACLH,YACAnC,OACAO,gBACAkB,cAAeA,EAAcC,QAC7BI,eACA3B,UACAE,kBACAI,mBACAE,gBACAa,iBAAkBA,EAAiBE,QACnCpC,YACAC,UACAC,gBACAI,6BACAC,uCACAC,oBACAG,UACAG,aACAE,qBACAS,SAEF,CACEoB,EACAnC,EACAO,EACAkB,EAAcC,QACdI,EACA3B,EACAE,EACAI,EACAE,EACAa,EAAiBE,QACjBpC,EACAC,EACAC,EACAK,EACAC,EACAG,EACAG,EACAE,EACAS,IAGJ,OAAOwB,EAAAC,QAAAC,cAACC,UAAQC,SAAQ,CAACN,MAAOA,GAAQtC,EAA4B"}
1
+ {"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ninterface IAuthProviderProps {\n projectId: string;\n baseUrl?: string;\n // allows to override the base URL that is used to fetch static files\n baseStaticUrl?: string;\n // If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // If true, last authenticated user will be stored on local storage and can accessed with getUser function\n storeLastAuthenticatedUser?: boolean;\n // If true, last authenticated user will not be removed after logout\n keepLastAuthenticatedUserAfterLogout?: boolean;\n // Use this option if the authentication is done via cookie, and configured with a different name\n // Currently, this is done using Descope Flows\n refreshCookieName?: string;\n // Function to get external token, for seamless migration from external system\n getExternalToken?: () => Promise<string>;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n sessionTokenViaCookie = false,\n persistTokens = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [isAuthenticated, setIsAuthenticated] = useState(false);\n\n const [isUserLoading, setIsUserLoading] = useState(false);\n const [isSessionLoading, setIsSessionLoading] = useState(false);\n\n // if oidc config is enabled, we attempt to finish the login, so we start as loading\n const [isOidcLoading, setIsOidcLoading] = useState(!!oidcConfig);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n sessionTokenViaCookie,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\n });\n\n useEffect(() => {\n if (sdk) {\n const unsubscribeSessionToken = sdk.onSessionTokenChange(setSession);\n const unsubscribeUser = sdk.onUserChange(setUser);\n const unsubscribeIsAuthenticated =\n sdk.onIsAuthenticatedChange(setIsAuthenticated);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetched = useRef(false);\n const isUserFetched = useRef(false);\n\n // if oidc config is enabled, and we have oidc params in the url\n // we will finish the login (this should run only once)\n useEffect(() => {\n if (sdk && oidcConfig && !isOidcFinishedLogin.current) {\n isOidcFinishedLogin.current = true;\n sdk.oidc.finishLoginIfNeed().finally(() => {\n setIsOidcLoading(false);\n // We want that the session will fetched only once\n isSessionFetched.current = true;\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // We want that the session will fetched only once\n if (isSessionFetched.current) return;\n isSessionFetched.current = true;\n\n setIsSessionLoading(true);\n withValidation(sdk?.refresh)().then(() => {\n setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n setUser,\n setSession,\n setIsAuthenticated,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n setUser,\n setSession,\n setIsAuthenticated,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["projectId","baseUrl","baseStaticUrl","sessionTokenViaCookie","persistTokens","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","children","user","setUser","useState","session","setSession","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","withValidation","refresh","then","fetchUser","me","value","useMemo","React","default","createElement","Context","Provider"],"mappings":"kQAyC6C,EAC3CA,YACAC,UAAU,GACVC,gBAAgB,GAChBC,yBAAwB,EACxBC,iBAAgB,EAChBC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,eAEA,MAAOC,EAAMC,GAAWC,EAAQA,YACzBC,EAASC,GAAcF,EAAQA,YAC/BG,EAAiBC,GAAsBJ,EAAQA,UAAC,IAEhDK,EAAeC,GAAoBN,EAAQA,UAAC,IAC5CO,EAAkBC,GAAuBR,EAAQA,UAAC,IAGlDS,EAAeC,GAAoBV,EAAAA,WAAWR,GAC/CmB,EAAsBC,UAAO,GAE7BC,EAAMC,EAAAA,QAAO,CACjB3B,YACAC,UACAG,gBACAD,wBACAE,aACAC,6BACAC,uCACAC,oBACAC,qBAGFmB,EAAAA,WAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBf,GACnDgB,EAAkBL,EAAIM,aAAapB,GACnCqB,EACJP,EAAIQ,wBAAwBjB,GAE9B,MAAO,KACLY,IACAE,IACAE,GAA4B,CAE/B,CACe,GACf,CAACP,IAEJ,MAAMS,EAAmBV,UAAO,GAC1BW,EAAgBX,UAAO,GAI7BG,EAAAA,WAAU,KACJF,GAAOrB,IAAemB,EAAoBa,UAC5Cb,EAAoBa,SAAU,EAC9BX,EAAIY,KAAKC,oBAAoBC,SAAQ,KACnCjB,GAAiB,GAEjBY,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,EAAAA,aAAY,KAE3BP,EAAiBE,UACrBF,EAAiBE,SAAU,EAE3BhB,GAAoB,GACpBsB,EAAAA,eAAejB,eAAAA,EAAKkB,QAApBD,GAA+BE,MAAK,KAClCxB,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEoB,EAAYJ,EAAAA,aAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBlB,GAAiB,GACjBwB,EAAAA,eAAejB,EAAIqB,GAAnBJ,GAAyBE,MAAK,KAC5B1B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEEsB,EAAQC,EAAAA,SACZ,KAAO,CACLH,YACAnC,OACAO,gBACAkB,cAAeA,EAAcC,QAC7BI,eACA3B,UACAE,kBACAI,mBACAE,gBACAa,iBAAkBA,EAAiBE,QACnCrC,YACAC,UACAC,gBACAI,6BACAC,uCACAC,oBACAI,UACAG,aACAE,qBACAS,SAEF,CACEoB,EACAnC,EACAO,EACAkB,EAAcC,QACdI,EACA3B,EACAE,EACAI,EACAE,EACAa,EAAiBE,QACjBrC,EACAC,EACAC,EACAK,EACAC,EACAI,EACAG,EACAE,EACAS,IAGJ,OAAOwB,EAAAC,QAAAC,cAACC,UAAQC,SAAQ,CAACN,MAAOA,GAAQtC,EAA4B"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),s=require("../../constants.js"),t=require("../../sdk.js");exports.default=({projectId:r,baseUrl:o,persistTokens:a,sessionTokenViaCookie:i,refreshCookieName:u,oidcConfig:n,storeLastAuthenticatedUser:d,keepLastAuthenticatedUserAfterLogout:c})=>e.useMemo((()=>{if(r)return t.default({projectId:r,baseUrl:o,sessionTokenViaCookie:i,baseHeaders:s.baseHeaders,persistTokens:a,refreshCookieName:u,oidcConfig:n,storeLastAuthenticatedUser:d,keepLastAuthenticatedUserAfterLogout:c,autoRefresh:!0})}),[r,o,i]);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("../../constants.js"),s=require("../../sdk.js");exports.default=({projectId:r,baseUrl:o,persistTokens:a,sessionTokenViaCookie:i,refreshCookieName:n,oidcConfig:u,storeLastAuthenticatedUser:d,keepLastAuthenticatedUserAfterLogout:k,getExternalToken:c})=>e.useMemo((()=>{if(r)return s.default({projectId:r,baseUrl:o,sessionTokenViaCookie:i,baseHeaders:t.baseHeaders,persistTokens:a,refreshCookieName:n,oidcConfig:u,storeLastAuthenticatedUser:d,keepLastAuthenticatedUserAfterLogout:k,autoRefresh:!0,getExternalToken:c})}),[r,o,i,c]);
2
2
  //# sourceMappingURL=useSdk.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSdk.js","sources":["../../../../src/components/AuthProvider/useSdk.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { baseHeaders } from '../../constants';\nimport createSdk from '../../sdk';\n\ntype Config = Pick<\n Parameters<typeof createSdk>[0],\n | 'projectId'\n | 'baseUrl'\n | 'persistTokens'\n | 'sessionTokenViaCookie'\n | 'storeLastAuthenticatedUser'\n | 'oidcConfig'\n | 'keepLastAuthenticatedUserAfterLogout'\n | 'refreshCookieName'\n>;\n\nexport default ({\n projectId,\n baseUrl,\n persistTokens,\n sessionTokenViaCookie,\n refreshCookieName,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n}: Config): ReturnType<typeof createSdk> =>\n useMemo(() => {\n if (!projectId) {\n return undefined;\n }\n return createSdk({\n projectId,\n baseUrl,\n sessionTokenViaCookie,\n baseHeaders,\n persistTokens,\n refreshCookieName,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n autoRefresh: true,\n });\n }, [projectId, baseUrl, sessionTokenViaCookie]);\n"],"names":["projectId","baseUrl","persistTokens","sessionTokenViaCookie","refreshCookieName","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","useMemo","createSdk","baseHeaders","autoRefresh"],"mappings":"qKAgBe,EACbA,YACAC,UACAC,gBACAC,wBACAC,oBACAC,aACAC,6BACAC,0CAEAC,EAAOA,SAAC,KACN,GAAKR,EAGL,OAAOS,UAAU,CACfT,YACAC,UACAE,oCACAO,EAAWA,YACXR,gBACAE,oBACAC,aACAC,6BACAC,uCACAI,aAAa,GACb,GACD,CAACX,EAAWC,EAASE"}
1
+ {"version":3,"file":"useSdk.js","sources":["../../../../src/components/AuthProvider/useSdk.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { baseHeaders } from '../../constants';\nimport createSdk from '../../sdk';\n\ntype Config = Pick<\n Parameters<typeof createSdk>[0],\n | 'projectId'\n | 'baseUrl'\n | 'persistTokens'\n | 'sessionTokenViaCookie'\n | 'storeLastAuthenticatedUser'\n | 'oidcConfig'\n | 'keepLastAuthenticatedUserAfterLogout'\n | 'refreshCookieName'\n | 'getExternalToken'\n>;\n\nexport default ({\n projectId,\n baseUrl,\n persistTokens,\n sessionTokenViaCookie,\n refreshCookieName,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n getExternalToken,\n}: Config): ReturnType<typeof createSdk> =>\n useMemo(() => {\n if (!projectId) {\n return undefined;\n }\n return createSdk({\n projectId,\n baseUrl,\n sessionTokenViaCookie,\n baseHeaders,\n persistTokens,\n refreshCookieName,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n autoRefresh: true,\n getExternalToken,\n });\n }, [projectId, baseUrl, sessionTokenViaCookie, getExternalToken]);\n"],"names":["projectId","baseUrl","persistTokens","sessionTokenViaCookie","refreshCookieName","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","getExternalToken","useMemo","createSdk","baseHeaders","autoRefresh"],"mappings":"qKAiBe,EACbA,YACAC,UACAC,gBACAC,wBACAC,oBACAC,aACAC,6BACAC,uCACAC,sBAEAC,EAAOA,SAAC,KACN,GAAKT,EAGL,OAAOU,UAAU,CACfV,YACAC,UACAE,oCACAQ,EAAWA,YACXT,gBACAE,oBACAC,aACAC,6BACAC,uCACAK,aAAa,EACbJ,oBACA,GACD,CAACR,EAAWC,EAASE,EAAuBK"}
@@ -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":"2.12.6"};
1
+ "use strict";const e="undefined"!=typeof window;exports.IS_BROWSER=e,exports.baseHeaders={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.13.0"};
2
2
  //# sourceMappingURL=constants.js.map
@@ -1,2 +1,2 @@
1
- import e,{useState as t,useRef as s,useEffect as r,useCallback as o,useMemo as n}from"react";import i from"../../hooks/Context.js";import{withValidation as c}from"../../utils.js";import a from"./useSdk.js";const u=({projectId:u,baseUrl:d="",baseStaticUrl:h="",sessionTokenViaCookie:f=!1,persistTokens:k=!0,oidcConfig:U,storeLastAuthenticatedUser:l=!0,keepLastAuthenticatedUserAfterLogout:m=!1,refreshCookieName:p="",children:L})=>{const[g,A]=t(),[C,S]=t(),[j,I]=t(!1),[b,T]=t(!1),[N,v]=t(!1),[x,F]=t(!!U),V=s(!1),y=a({projectId:u,baseUrl:d,persistTokens:k,sessionTokenViaCookie:f,oidcConfig:U,storeLastAuthenticatedUser:l,keepLastAuthenticatedUserAfterLogout:m,refreshCookieName:p});r((()=>{if(y){const e=y.onSessionTokenChange(S),t=y.onUserChange(A),s=y.onIsAuthenticatedChange(I);return()=>{e(),t(),s()}}}),[y]);const E=s(!1),O=s(!1);r((()=>{y&&U&&!V.current&&(V.current=!0,y.oidc.finishLoginIfNeed().finally((()=>{F(!1),E.current=!0})))}),[]);const P=o((()=>{E.current||(E.current=!0,v(!0),c(null==y?void 0:y.refresh)().then((()=>{v(!1)})))}),[y]),q=o((()=>{O.current||(O.current=!0,T(!0),c(y.me)().then((()=>{T(!1)})))}),[y]),w=n((()=>({fetchUser:q,user:g,isUserLoading:b,isUserFetched:O.current,fetchSession:P,session:C,isAuthenticated:j,isSessionLoading:N,isOidcLoading:x,isSessionFetched:E.current,projectId:u,baseUrl:d,baseStaticUrl:h,storeLastAuthenticatedUser:l,keepLastAuthenticatedUserAfterLogout:m,refreshCookieName:p,setUser:A,setSession:S,setIsAuthenticated:I,sdk:y})),[q,g,b,O.current,P,C,j,N,x,E.current,u,d,h,m,p,A,S,I,y]);return e.createElement(i.Provider,{value:w},L)};export{u as default};
1
+ import e,{useState as t,useRef as s,useEffect as r,useCallback as o,useMemo as n}from"react";import i from"../../hooks/Context.js";import{withValidation as a}from"../../utils.js";import c from"./useSdk.js";const u=({projectId:u,baseUrl:d="",baseStaticUrl:h="",sessionTokenViaCookie:f=!1,persistTokens:k=!0,oidcConfig:l,storeLastAuthenticatedUser:U=!0,keepLastAuthenticatedUserAfterLogout:g=!1,refreshCookieName:m="",getExternalToken:p,children:L})=>{const[A,C]=t(),[S,T]=t(),[j,I]=t(!1),[b,x]=t(!1),[N,v]=t(!1),[E,F]=t(!!l),V=s(!1),y=c({projectId:u,baseUrl:d,persistTokens:k,sessionTokenViaCookie:f,oidcConfig:l,storeLastAuthenticatedUser:U,keepLastAuthenticatedUserAfterLogout:g,refreshCookieName:m,getExternalToken:p});r((()=>{if(y){const e=y.onSessionTokenChange(T),t=y.onUserChange(C),s=y.onIsAuthenticatedChange(I);return()=>{e(),t(),s()}}}),[y]);const O=s(!1),P=s(!1);r((()=>{y&&l&&!V.current&&(V.current=!0,y.oidc.finishLoginIfNeed().finally((()=>{F(!1),O.current=!0})))}),[]);const q=o((()=>{O.current||(O.current=!0,v(!0),a(null==y?void 0:y.refresh)().then((()=>{v(!1)})))}),[y]),w=o((()=>{P.current||(P.current=!0,x(!0),a(y.me)().then((()=>{x(!1)})))}),[y]),z=n((()=>({fetchUser:w,user:A,isUserLoading:b,isUserFetched:P.current,fetchSession:q,session:S,isAuthenticated:j,isSessionLoading:N,isOidcLoading:E,isSessionFetched:O.current,projectId:u,baseUrl:d,baseStaticUrl:h,storeLastAuthenticatedUser:U,keepLastAuthenticatedUserAfterLogout:g,refreshCookieName:m,setUser:C,setSession:T,setIsAuthenticated:I,sdk:y})),[w,A,b,P.current,q,S,j,N,E,O.current,u,d,h,g,m,C,T,I,y]);return e.createElement(i.Provider,{value:z},L)};export{u as default};
2
2
  //# sourceMappingURL=AuthProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ninterface IAuthProviderProps {\n projectId: string;\n baseUrl?: string;\n // allows to override the base URL that is used to fetch static files\n baseStaticUrl?: string;\n // If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // If true, last authenticated user will be stored on local storage and can accessed with getUser function\n storeLastAuthenticatedUser?: boolean;\n // If true, last authenticated user will not be removed after logout\n keepLastAuthenticatedUserAfterLogout?: boolean;\n // Use this option if the authentication is done via cookie, and configured with a different name\n // Currently, this is done using Descope Flows\n refreshCookieName?: string;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n sessionTokenViaCookie = false,\n persistTokens = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [isAuthenticated, setIsAuthenticated] = useState(false);\n\n const [isUserLoading, setIsUserLoading] = useState(false);\n const [isSessionLoading, setIsSessionLoading] = useState(false);\n\n // if oidc config is enabled, we attempt to finish the login, so we start as loading\n const [isOidcLoading, setIsOidcLoading] = useState(!!oidcConfig);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n sessionTokenViaCookie,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n });\n\n useEffect(() => {\n if (sdk) {\n const unsubscribeSessionToken = sdk.onSessionTokenChange(setSession);\n const unsubscribeUser = sdk.onUserChange(setUser);\n const unsubscribeIsAuthenticated =\n sdk.onIsAuthenticatedChange(setIsAuthenticated);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetched = useRef(false);\n const isUserFetched = useRef(false);\n\n // if oidc config is enabled, and we have oidc params in the url\n // we will finish the login (this should run only once)\n useEffect(() => {\n if (sdk && oidcConfig && !isOidcFinishedLogin.current) {\n isOidcFinishedLogin.current = true;\n sdk.oidc.finishLoginIfNeed().finally(() => {\n setIsOidcLoading(false);\n // We want that the session will fetched only once\n isSessionFetched.current = true;\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // We want that the session will fetched only once\n if (isSessionFetched.current) return;\n isSessionFetched.current = true;\n\n setIsSessionLoading(true);\n withValidation(sdk?.refresh)().then(() => {\n setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n setUser,\n setSession,\n setIsAuthenticated,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n setUser,\n setSession,\n setIsAuthenticated,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["AuthProvider","projectId","baseUrl","baseStaticUrl","sessionTokenViaCookie","persistTokens","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","children","user","setUser","useState","session","setSession","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","withValidation","refresh","then","fetchUser","me","value","useMemo","React","createElement","Context","Provider"],"mappings":"8MAuCA,MAAMA,EAAuC,EAC3CC,YACAC,UAAU,GACVC,gBAAgB,GAChBC,yBAAwB,EACxBC,iBAAgB,EAChBC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,eAEA,MAAOC,EAAMC,GAAWC,KACjBC,EAASC,GAAcF,KACvBG,EAAiBC,GAAsBJ,GAAS,IAEhDK,EAAeC,GAAoBN,GAAS,IAC5CO,EAAkBC,GAAuBR,GAAS,IAGlDS,EAAeC,GAAoBV,IAAWP,GAC/CkB,EAAsBC,GAAO,GAE7BC,EAAMC,EAAO,CACjB1B,YACAC,UACAG,gBACAD,wBACAE,aACAC,6BACAC,uCACAC,sBAGFmB,GAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBf,GACnDgB,EAAkBL,EAAIM,aAAapB,GACnCqB,EACJP,EAAIQ,wBAAwBjB,GAE9B,MAAO,KACLY,IACAE,IACAE,GAA4B,CAE/B,CACe,GACf,CAACP,IAEJ,MAAMS,EAAmBV,GAAO,GAC1BW,EAAgBX,GAAO,GAI7BG,GAAU,KACJF,GAAOpB,IAAekB,EAAoBa,UAC5Cb,EAAoBa,SAAU,EAC9BX,EAAIY,KAAKC,oBAAoBC,SAAQ,KACnCjB,GAAiB,GAEjBY,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,GAAY,KAE3BP,EAAiBE,UACrBF,EAAiBE,SAAU,EAE3BhB,GAAoB,GACpBsB,EAAejB,eAAAA,EAAKkB,QAApBD,GAA+BE,MAAK,KAClCxB,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEoB,EAAYJ,GAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBlB,GAAiB,GACjBwB,EAAejB,EAAIqB,GAAnBJ,GAAyBE,MAAK,KAC5B1B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEEsB,EAAQC,GACZ,KAAO,CACLH,YACAnC,OACAO,gBACAkB,cAAeA,EAAcC,QAC7BI,eACA3B,UACAE,kBACAI,mBACAE,gBACAa,iBAAkBA,EAAiBE,QACnCpC,YACAC,UACAC,gBACAI,6BACAC,uCACAC,oBACAG,UACAG,aACAE,qBACAS,SAEF,CACEoB,EACAnC,EACAO,EACAkB,EAAcC,QACdI,EACA3B,EACAE,EACAI,EACAE,EACAa,EAAiBE,QACjBpC,EACAC,EACAC,EACAK,EACAC,EACAG,EACAG,EACAE,EACAS,IAGJ,OAAOwB,EAAAC,cAACC,EAAQC,SAAQ,CAACL,MAAOA,GAAQtC,EAA4B"}
1
+ {"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ninterface IAuthProviderProps {\n projectId: string;\n baseUrl?: string;\n // allows to override the base URL that is used to fetch static files\n baseStaticUrl?: string;\n // If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // If true, last authenticated user will be stored on local storage and can accessed with getUser function\n storeLastAuthenticatedUser?: boolean;\n // If true, last authenticated user will not be removed after logout\n keepLastAuthenticatedUserAfterLogout?: boolean;\n // Use this option if the authentication is done via cookie, and configured with a different name\n // Currently, this is done using Descope Flows\n refreshCookieName?: string;\n // Function to get external token, for seamless migration from external system\n getExternalToken?: () => Promise<string>;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n sessionTokenViaCookie = false,\n persistTokens = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [isAuthenticated, setIsAuthenticated] = useState(false);\n\n const [isUserLoading, setIsUserLoading] = useState(false);\n const [isSessionLoading, setIsSessionLoading] = useState(false);\n\n // if oidc config is enabled, we attempt to finish the login, so we start as loading\n const [isOidcLoading, setIsOidcLoading] = useState(!!oidcConfig);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n sessionTokenViaCookie,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\n });\n\n useEffect(() => {\n if (sdk) {\n const unsubscribeSessionToken = sdk.onSessionTokenChange(setSession);\n const unsubscribeUser = sdk.onUserChange(setUser);\n const unsubscribeIsAuthenticated =\n sdk.onIsAuthenticatedChange(setIsAuthenticated);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetched = useRef(false);\n const isUserFetched = useRef(false);\n\n // if oidc config is enabled, and we have oidc params in the url\n // we will finish the login (this should run only once)\n useEffect(() => {\n if (sdk && oidcConfig && !isOidcFinishedLogin.current) {\n isOidcFinishedLogin.current = true;\n sdk.oidc.finishLoginIfNeed().finally(() => {\n setIsOidcLoading(false);\n // We want that the session will fetched only once\n isSessionFetched.current = true;\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // We want that the session will fetched only once\n if (isSessionFetched.current) return;\n isSessionFetched.current = true;\n\n setIsSessionLoading(true);\n withValidation(sdk?.refresh)().then(() => {\n setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n setUser,\n setSession,\n setIsAuthenticated,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n setUser,\n setSession,\n setIsAuthenticated,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["AuthProvider","projectId","baseUrl","baseStaticUrl","sessionTokenViaCookie","persistTokens","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","children","user","setUser","useState","session","setSession","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","withValidation","refresh","then","fetchUser","me","value","useMemo","React","createElement","Context","Provider"],"mappings":"8MAyCM,MAAAA,EAAuC,EAC3CC,YACAC,UAAU,GACVC,gBAAgB,GAChBC,yBAAwB,EACxBC,iBAAgB,EAChBC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,eAEA,MAAOC,EAAMC,GAAWC,KACjBC,EAASC,GAAcF,KACvBG,EAAiBC,GAAsBJ,GAAS,IAEhDK,EAAeC,GAAoBN,GAAS,IAC5CO,EAAkBC,GAAuBR,GAAS,IAGlDS,EAAeC,GAAoBV,IAAWR,GAC/CmB,EAAsBC,GAAO,GAE7BC,EAAMC,EAAO,CACjB3B,YACAC,UACAG,gBACAD,wBACAE,aACAC,6BACAC,uCACAC,oBACAC,qBAGFmB,GAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBf,GACnDgB,EAAkBL,EAAIM,aAAapB,GACnCqB,EACJP,EAAIQ,wBAAwBjB,GAE9B,MAAO,KACLY,IACAE,IACAE,GAA4B,CAE/B,CACe,GACf,CAACP,IAEJ,MAAMS,EAAmBV,GAAO,GAC1BW,EAAgBX,GAAO,GAI7BG,GAAU,KACJF,GAAOrB,IAAemB,EAAoBa,UAC5Cb,EAAoBa,SAAU,EAC9BX,EAAIY,KAAKC,oBAAoBC,SAAQ,KACnCjB,GAAiB,GAEjBY,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,GAAY,KAE3BP,EAAiBE,UACrBF,EAAiBE,SAAU,EAE3BhB,GAAoB,GACpBsB,EAAejB,eAAAA,EAAKkB,QAApBD,GAA+BE,MAAK,KAClCxB,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEoB,EAAYJ,GAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBlB,GAAiB,GACjBwB,EAAejB,EAAIqB,GAAnBJ,GAAyBE,MAAK,KAC5B1B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEEsB,EAAQC,GACZ,KAAO,CACLH,YACAnC,OACAO,gBACAkB,cAAeA,EAAcC,QAC7BI,eACA3B,UACAE,kBACAI,mBACAE,gBACAa,iBAAkBA,EAAiBE,QACnCrC,YACAC,UACAC,gBACAI,6BACAC,uCACAC,oBACAI,UACAG,aACAE,qBACAS,SAEF,CACEoB,EACAnC,EACAO,EACAkB,EAAcC,QACdI,EACA3B,EACAE,EACAI,EACAE,EACAa,EAAiBE,QACjBrC,EACAC,EACAC,EACAK,EACAC,EACAI,EACAG,EACAE,EACAS,IAGJ,OAAOwB,EAAAC,cAACC,EAAQC,SAAQ,CAACL,MAAOA,GAAQtC,EAA4B"}
@@ -1,2 +1,2 @@
1
- import{useMemo as e}from"react";import{baseHeaders as t}from"../../constants.js";import o from"../../sdk.js";var s=({projectId:s,baseUrl:r,persistTokens:a,sessionTokenViaCookie:i,refreshCookieName:n,oidcConfig:f,storeLastAuthenticatedUser:d,keepLastAuthenticatedUserAfterLogout:k})=>e((()=>{if(s)return o({projectId:s,baseUrl:r,sessionTokenViaCookie:i,baseHeaders:t,persistTokens:a,refreshCookieName:n,oidcConfig:f,storeLastAuthenticatedUser:d,keepLastAuthenticatedUserAfterLogout:k,autoRefresh:!0})}),[s,r,i]);export{s as default};
1
+ import{useMemo as e}from"react";import{baseHeaders as t}from"../../constants.js";import o from"../../sdk.js";var s=({projectId:s,baseUrl:r,persistTokens:a,sessionTokenViaCookie:i,refreshCookieName:n,oidcConfig:k,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:d,getExternalToken:c})=>e((()=>{if(s)return o({projectId:s,baseUrl:r,sessionTokenViaCookie:i,baseHeaders:t,persistTokens:a,refreshCookieName:n,oidcConfig:k,storeLastAuthenticatedUser:f,keepLastAuthenticatedUserAfterLogout:d,autoRefresh:!0,getExternalToken:c})}),[s,r,i,c]);export{s as default};
2
2
  //# sourceMappingURL=useSdk.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSdk.js","sources":["../../../../src/components/AuthProvider/useSdk.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { baseHeaders } from '../../constants';\nimport createSdk from '../../sdk';\n\ntype Config = Pick<\n Parameters<typeof createSdk>[0],\n | 'projectId'\n | 'baseUrl'\n | 'persistTokens'\n | 'sessionTokenViaCookie'\n | 'storeLastAuthenticatedUser'\n | 'oidcConfig'\n | 'keepLastAuthenticatedUserAfterLogout'\n | 'refreshCookieName'\n>;\n\nexport default ({\n projectId,\n baseUrl,\n persistTokens,\n sessionTokenViaCookie,\n refreshCookieName,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n}: Config): ReturnType<typeof createSdk> =>\n useMemo(() => {\n if (!projectId) {\n return undefined;\n }\n return createSdk({\n projectId,\n baseUrl,\n sessionTokenViaCookie,\n baseHeaders,\n persistTokens,\n refreshCookieName,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n autoRefresh: true,\n });\n }, [projectId, baseUrl, sessionTokenViaCookie]);\n"],"names":["useSdk","projectId","baseUrl","persistTokens","sessionTokenViaCookie","refreshCookieName","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","useMemo","createSdk","baseHeaders","autoRefresh"],"mappings":"6GAgBA,IAAeA,EAAA,EACbC,YACAC,UACAC,gBACAC,wBACAC,oBACAC,aACAC,6BACAC,0CAEAC,GAAQ,KACN,GAAKR,EAGL,OAAOS,EAAU,CACfT,YACAC,UACAE,wBACAO,cACAR,gBACAE,oBACAC,aACAC,6BACAC,uCACAI,aAAa,GACb,GACD,CAACX,EAAWC,EAASE"}
1
+ {"version":3,"file":"useSdk.js","sources":["../../../../src/components/AuthProvider/useSdk.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { baseHeaders } from '../../constants';\nimport createSdk from '../../sdk';\n\ntype Config = Pick<\n Parameters<typeof createSdk>[0],\n | 'projectId'\n | 'baseUrl'\n | 'persistTokens'\n | 'sessionTokenViaCookie'\n | 'storeLastAuthenticatedUser'\n | 'oidcConfig'\n | 'keepLastAuthenticatedUserAfterLogout'\n | 'refreshCookieName'\n | 'getExternalToken'\n>;\n\nexport default ({\n projectId,\n baseUrl,\n persistTokens,\n sessionTokenViaCookie,\n refreshCookieName,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n getExternalToken,\n}: Config): ReturnType<typeof createSdk> =>\n useMemo(() => {\n if (!projectId) {\n return undefined;\n }\n return createSdk({\n projectId,\n baseUrl,\n sessionTokenViaCookie,\n baseHeaders,\n persistTokens,\n refreshCookieName,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n autoRefresh: true,\n getExternalToken,\n });\n }, [projectId, baseUrl, sessionTokenViaCookie, getExternalToken]);\n"],"names":["useSdk","projectId","baseUrl","persistTokens","sessionTokenViaCookie","refreshCookieName","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","getExternalToken","useMemo","createSdk","baseHeaders","autoRefresh"],"mappings":"6GAiBA,IAAeA,EAAA,EACbC,YACAC,UACAC,gBACAC,wBACAC,oBACAC,aACAC,6BACAC,uCACAC,sBAEAC,GAAQ,KACN,GAAKT,EAGL,OAAOU,EAAU,CACfV,YACAC,UACAE,wBACAQ,cACAT,gBACAE,oBACAC,aACAC,6BACAC,uCACAK,aAAa,EACbJ,oBACA,GACD,CAACR,EAAWC,EAASE,EAAuBK"}
@@ -1,2 +1,2 @@
1
- const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.12.6"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
1
+ const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.13.0"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
2
2
  //# sourceMappingURL=constants.js.map
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ interface IAuthProviderProps {
23
23
  storeLastAuthenticatedUser?: boolean;
24
24
  keepLastAuthenticatedUserAfterLogout?: boolean;
25
25
  refreshCookieName?: string;
26
+ getExternalToken?: () => Promise<string>;
26
27
  children?: React.ReactNode;
27
28
  }
28
29
  declare const AuthProvider: FC<IAuthProviderProps>;
@@ -65,6 +66,7 @@ declare const createSdkWrapper: <P extends Omit<{
65
66
  };
66
67
  } & {
67
68
  oidcConfig?: _descope_web_js_sdk.OidcConfig;
69
+ getExternalToken?: () => Promise<string>;
68
70
  } & {
69
71
  fpKey?: string;
70
72
  fpLoad?: boolean;