@descope/react-sdk 3.3.17 → 3.3.19

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.
@@ -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 o(e){return e&&e.__esModule?e:{default:e}}var n=o(e);exports.default=({projectId:o,baseUrl:i="",baseStaticUrl:a="",baseCdnUrl:u="",sessionTokenViaCookie:c=!1,refreshTokenViaCookie:d=!1,hooks:f,persistTokens:h=!0,autoRefresh:l=!0,oidcConfig:k,storeLastAuthenticatedUser:S=!0,keepLastAuthenticatedUserAfterLogout:C=!1,refreshCookieName:g="",getExternalToken:U,customStorage:p,children:L})=>{const[m,A]=e.useState(),[b,T]=e.useState(),[j,v]=e.useState(),[I,V]=e.useState(!1),[x,E]=e.useState(!1),[R,q]=e.useState(!1),[N,_]=e.useState(!!k),[F,M]=e.useState(!1),w=e.useRef(!1),y=r.default({projectId:o,baseUrl:i,persistTokens:h,autoRefresh:l,sessionTokenViaCookie:c,refreshTokenViaCookie:d,hooks:f,oidcConfig:k,storeLastAuthenticatedUser:S,keepLastAuthenticatedUserAfterLogout:C,refreshCookieName:g,getExternalToken:U,customStorage:p});e.useEffect((()=>{if(y){const e=y.onSessionTokenChange(T),t=y.onUserChange(A),s=y.onIsAuthenticatedChange(V),r=y.onClaimsChange(v);return()=>{e(),t(),s(),r()}}}),[y]);const O=e.useRef(!1),P=e.useRef(!1);e.useEffect((()=>{y&&k&&!w.current&&(w.current=!0,y.oidc.finishLoginIfNeed().finally((()=>{_(!1),O.current=!0,M(!0)})))}),[]);const B=e.useCallback((()=>{if(s.isDescopeBridge())return;if(O.current)return;O.current=!0,q(!0);const e=()=>{q(!1),M(!0)};s.withValidation(null==y?void 0:y.refresh)(void 0,!0).then(e,e)}),[y]),D=e.useCallback((()=>{if(P.current)return;P.current=!0,E(!0);const e=()=>E(!1);s.withValidation(y.me)().then(e,e)}),[y]),z=e.useMemo((()=>({fetchUser:D,user:m,isUserLoading:x,isUserFetched:P.current,fetchSession:B,session:b,isAuthenticated:I,isSessionLoading:R,isOidcLoading:N,isSessionFetchStarted:O.current,isSessionFetchCompleted:F,projectId:o,baseUrl:i,baseStaticUrl:a,baseCdnUrl:u,storeLastAuthenticatedUser:S,keepLastAuthenticatedUserAfterLogout:C,refreshCookieName:g,customStorage:p,setUser:A,setSession:T,setIsAuthenticated:V,claims:j,sdk:y})),[D,m,x,P.current,B,b,I,R,N,O.current,F,o,i,a,u,C,g,p,A,T,V,j,y]);return n.default.createElement(t.default.Provider,{value:z},L)};
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 o(e){return e&&e.__esModule?e:{default:e}}var n=o(e);exports.default=({projectId:o,baseUrl:i="",baseStaticUrl:a="",baseCdnUrl:u="",sessionTokenViaCookie:c=!1,refreshTokenViaCookie:d=!1,hooks:f,persistTokens:h=!0,autoRefresh:l=!0,oidcConfig:k,storeLastAuthenticatedUser:S=!0,keepLastAuthenticatedUserAfterLogout:C=!1,refreshCookieName:g="",getExternalToken:U,customStorage:p,children:m})=>{const[L,A]=e.useState(),[b,T]=e.useState(),[j,v]=e.useState(),[I,V]=e.useState(!1),[x,E]=e.useState(!1),[R,q]=e.useState(!1),[F,N]=e.useState(!!k),[_,M]=e.useState(!1),[w,y]=e.useState(!1),O=e.useRef(!1),P=r.default({projectId:o,baseUrl:i,persistTokens:h,autoRefresh:l,sessionTokenViaCookie:c,refreshTokenViaCookie:d,hooks:f,oidcConfig:k,storeLastAuthenticatedUser:S,keepLastAuthenticatedUserAfterLogout:C,refreshCookieName:g,getExternalToken:U,customStorage:p});e.useEffect((()=>{if(P){const e=P.onSessionTokenChange(T),t=P.onUserChange(A),s=P.onIsAuthenticatedChange(V),r=P.onClaimsChange(v);return()=>{e(),t(),s(),r()}}}),[P]);const B=e.useRef(!1),D=e.useRef(!1);e.useEffect((()=>{P&&k&&!O.current&&(O.current=!0,P.oidc.finishLoginIfNeed().finally((()=>{N(!1),B.current=!0,M(!0)})))}),[]);const z=e.useCallback((()=>{if(s.isDescopeBridge())return;if(B.current)return;B.current=!0,q(!0);const e=()=>{q(!1),M(!0)};s.withValidation(null==P?void 0:P.refresh)(void 0,!0).then(e,e)}),[P]),G=e.useCallback((()=>{if(D.current)return;D.current=!0,E(!0);const e=()=>{E(!1),y(!0)};s.withValidation(P.me)().then(e,e)}),[P]),H=e.useMemo((()=>({fetchUser:G,user:L,isUserLoading:x,isUserFetchStarted:D.current,isUserFetchCompleted:w,fetchSession:z,session:b,isAuthenticated:I,isSessionLoading:R,isOidcLoading:F,isSessionFetchStarted:B.current,isSessionFetchCompleted:_,projectId:o,baseUrl:i,baseStaticUrl:a,baseCdnUrl:u,storeLastAuthenticatedUser:S,keepLastAuthenticatedUserAfterLogout:C,refreshCookieName:g,customStorage:p,setUser:A,setSession:T,setIsAuthenticated:V,claims:j,sdk:P})),[G,L,x,D.current,w,z,b,I,R,F,B.current,_,o,i,a,u,C,g,p,A,T,V,j,P]);return n.default.createElement(t.default.Provider,{value:H},m)};
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 {\n CookieConfig,\n OidcConfig,\n AutoRefreshConfig,\n} from '@descope/web-js-sdk';\nimport { Claims } from '@descope/core-js-sdk';\nimport { CustomStorage } from '@descope/web-component';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { isDescopeBridge, withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ntype Hooks = Parameters<typeof useSdk>[0]['hooks'];\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 // allows to override the base URL that is used to fetch external script files\n baseCdnUrl?: string;\n // Default is true. If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // Default is true. If true, the SDK will automatically refresh the session token when it is about to expire.\n // Pass `{ customActivityTracking: true }` to skip refresh for idle users — you must call `sdk.markUserActive()` to signal activity.\n autoRefresh?: AutoRefreshConfig;\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 true, refresh token will be stored on cookie. Otherwise, the refresh token will be\n // stored on local storage and can be accessed with getRefreshToken function\n // Use this option if you need server-side access to the refresh token (e.g., in Next.js middleware)\n // to enable refreshing sessions on the server before they expire\n refreshTokenViaCookie?: CookieConfig;\n hooks?: Hooks;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // Default is true. 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 // Custom storage object for authentication related data\n customStorage?: CustomStorage;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n refreshTokenViaCookie = false,\n hooks = undefined,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n customStorage = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [claims, setClaims] = useState<Claims>();\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 // flips once when the first session fetch settles - unlike isSessionLoading, this change\n // can't be lost if React batches the loading true/false updates into a single render\n const [isSessionFetchCompleted, setIsSessionFetchCompleted] = useState(false);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n autoRefresh,\n sessionTokenViaCookie,\n refreshTokenViaCookie,\n hooks,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\n customStorage,\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 const unsubscribeClaims = sdk.onClaimsChange(setClaims);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n unsubscribeClaims();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetchStarted = 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 // finishing the OIDC login already fetched the session, so mark the fetch as both\n // started (fetchSession won't run again) and completed, even though it never ran\n isSessionFetchStarted.current = true;\n setIsSessionFetchCompleted(true);\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // Don't load the session in native flows, though we'd usually not get here at all from useSession in this case\n if (isDescopeBridge()) return;\n\n // We want that the session will fetched only once\n if (isSessionFetchStarted.current) return;\n isSessionFetchStarted.current = true;\n\n setIsSessionLoading(true);\n const stopSessionLoading = () => {\n setIsSessionLoading(false);\n setIsSessionFetchCompleted(true);\n };\n // Clear the loading state on both fulfilment and rejection. A rejected\n // refresh (e.g. a transient network failure on the proactive refresh) must\n // still clear `isSessionLoading` - `isSessionFetchStarted` is already set so\n // `fetchSession` never re-runs, and consumers (e.g. useSession) would\n // otherwise hang on \"loading\" forever despite a valid session.\n withValidation(sdk?.refresh)(undefined, true).then(\n stopSessionLoading,\n stopSessionLoading,\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 // Clear the loading state on both fulfilment and rejection so a failed\n // `me()` doesn't leave `isUserLoading` stuck `true` (see fetchSession).\n const stopUserLoading = () => setIsUserLoading(false);\n withValidation(sdk.me)().then(stopUserLoading, stopUserLoading);\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 isSessionFetchStarted: isSessionFetchStarted.current,\n isSessionFetchCompleted,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetchStarted.current,\n isSessionFetchCompleted,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["projectId","baseUrl","baseStaticUrl","baseCdnUrl","sessionTokenViaCookie","refreshTokenViaCookie","hooks","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","customStorage","children","user","setUser","useState","session","setSession","claims","setClaims","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isSessionFetchCompleted","setIsSessionFetchCompleted","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","unsubscribeClaims","onClaimsChange","isSessionFetchStarted","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","isDescopeBridge","stopSessionLoading","withValidation","refresh","undefined","then","fetchUser","stopUserLoading","me","value","useMemo","React","default","createElement","Context","Provider"],"mappings":"kQA8D6C,EAC3CA,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,yBAAwB,EACxBC,yBAAwB,EACxBC,QACAC,iBAAgB,EAChBC,eAAc,EACdC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,gBACAC,eAEA,MAAOC,EAAMC,GAAWC,EAAQA,YACzBC,EAASC,GAAcF,EAAQA,YAC/BG,EAAQC,GAAaJ,EAAQA,YAC7BK,EAAiBC,GAAsBN,EAAQA,UAAC,IAEhDO,EAAeC,GAAoBR,EAAQA,UAAC,IAC5CS,EAAkBC,GAAuBV,EAAQA,UAAC,IAGlDW,EAAeC,GAAoBZ,EAAAA,WAAWT,IAG9CsB,EAAyBC,GAA8Bd,EAAQA,UAAC,GACjEe,EAAsBC,UAAO,GAE7BC,EAAMC,EAAAA,QAAO,CACjBpC,YACAC,UACAM,gBACAC,cACAJ,wBACAC,wBACAC,QACAG,aACAC,6BACAC,uCACAC,oBACAC,mBACAC,kBAGFuB,EAAAA,WAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBnB,GACnDoB,EAAkBL,EAAIM,aAAaxB,GACnCyB,EACJP,EAAIQ,wBAAwBnB,GACxBoB,EAAoBT,EAAIU,eAAevB,GAE7C,MAAO,KACLgB,IACAE,IACAE,IACAE,GAAmB,CAEtB,CACe,GACf,CAACT,IAEJ,MAAMW,EAAwBZ,UAAO,GAC/Ba,EAAgBb,UAAO,GAI7BG,EAAAA,WAAU,KACJF,GAAO1B,IAAewB,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCrB,GAAiB,GAGjBgB,EAAsBE,SAAU,EAChChB,GAA2B,EAAK,IAEnC,GACA,IAEH,MAAMoB,EAAeC,EAAAA,aAAY,KAE/B,GAAIC,oBAAmB,OAGvB,GAAIR,EAAsBE,QAAS,OACnCF,EAAsBE,SAAU,EAEhCpB,GAAoB,GACpB,MAAM2B,EAAqB,KACzB3B,GAAoB,GACpBI,GAA2B,EAAK,EAOlCwB,EAAcA,eAACrB,eAAAA,EAAKsB,QAApBD,MAA6BE,GAAW,GAAMC,KAC5CJ,EACAA,EACD,GACA,CAACpB,IAEEyB,EAAYP,EAAAA,aAAY,KAE5B,GAAIN,EAAcC,QAAS,OAC3BD,EAAcC,SAAU,EAExBtB,GAAiB,GAGjB,MAAMmC,EAAkB,IAAMnC,GAAiB,GAC/C8B,EAAcA,eAACrB,EAAI2B,GAAnBN,GAAyBG,KAAKE,EAAiBA,EAAgB,GAC9D,CAAC1B,IAEE4B,EAAQC,EAAAA,SACZ,KAAO,CACLJ,YACA5C,OACAS,gBACAsB,cAAeA,EAAcC,QAC7BI,eACAjC,UACAI,kBACAI,mBACAE,gBACAiB,sBAAuBA,EAAsBE,QAC7CjB,0BACA/B,YACAC,UACAC,gBACAC,aACAO,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAc,SAEF,CACEyB,EACA5C,EACAS,EACAsB,EAAcC,QACdI,EACAjC,EACAI,EACAI,EACAE,EACAiB,EAAsBE,QACtBjB,EACA/B,EACAC,EACAC,EACAC,EACAQ,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAc,IAGJ,OAAO8B,EAAAC,QAAAC,cAACC,UAAQC,SAAQ,CAACN,MAAOA,GAAQhD,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 {\n CookieConfig,\n OidcConfig,\n AutoRefreshConfig,\n} from '@descope/web-js-sdk';\nimport { Claims } from '@descope/core-js-sdk';\nimport { CustomStorage } from '@descope/web-component';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { isDescopeBridge, withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ntype Hooks = Parameters<typeof useSdk>[0]['hooks'];\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 // allows to override the base URL that is used to fetch external script files\n baseCdnUrl?: string;\n // Default is true. If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // Default is true. If true, the SDK will automatically refresh the session token when it is about to expire.\n // Pass `{ customActivityTracking: true }` to skip refresh for idle users — you must call `sdk.markUserActive()` to signal activity.\n autoRefresh?: AutoRefreshConfig;\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 true, refresh token will be stored on cookie. Otherwise, the refresh token will be\n // stored on local storage and can be accessed with getRefreshToken function\n // Use this option if you need server-side access to the refresh token (e.g., in Next.js middleware)\n // to enable refreshing sessions on the server before they expire\n refreshTokenViaCookie?: CookieConfig;\n hooks?: Hooks;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // Default is true. 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 // Custom storage object for authentication related data\n customStorage?: CustomStorage;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n refreshTokenViaCookie = false,\n hooks = undefined,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n customStorage = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [claims, setClaims] = useState<Claims>();\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 // flips once when the first session fetch settles - unlike isSessionLoading, this change\n // can't be lost if React batches the loading true/false updates into a single render\n const [isSessionFetchCompleted, setIsSessionFetchCompleted] = useState(false);\n // same as isSessionFetchCompleted, for the user fetch\n const [isUserFetchCompleted, setIsUserFetchCompleted] = useState(false);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n autoRefresh,\n sessionTokenViaCookie,\n refreshTokenViaCookie,\n hooks,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\n customStorage,\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 const unsubscribeClaims = sdk.onClaimsChange(setClaims);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n unsubscribeClaims();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetchStarted = useRef(false);\n const isUserFetchStarted = 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 // finishing the OIDC login already fetched the session, so mark the fetch as both\n // started (fetchSession won't run again) and completed, even though it never ran\n isSessionFetchStarted.current = true;\n setIsSessionFetchCompleted(true);\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // Don't load the session in native flows, though we'd usually not get here at all from useSession in this case\n if (isDescopeBridge()) return;\n\n // We want that the session will fetched only once\n if (isSessionFetchStarted.current) return;\n isSessionFetchStarted.current = true;\n\n setIsSessionLoading(true);\n const stopSessionLoading = () => {\n setIsSessionLoading(false);\n setIsSessionFetchCompleted(true);\n };\n // Clear the loading state on both fulfilment and rejection. A rejected\n // refresh (e.g. a transient network failure on the proactive refresh) must\n // still clear `isSessionLoading` - `isSessionFetchStarted` is already set so\n // `fetchSession` never re-runs, and consumers (e.g. useSession) would\n // otherwise hang on \"loading\" forever despite a valid session.\n withValidation(sdk?.refresh)(undefined, true).then(\n stopSessionLoading,\n stopSessionLoading,\n );\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetchStarted.current) return;\n isUserFetchStarted.current = true;\n\n setIsUserLoading(true);\n // Clear the loading state on both fulfilment and rejection so a failed\n // `me()` doesn't leave `isUserLoading` stuck `true` (see fetchSession).\n const stopUserLoading = () => {\n setIsUserLoading(false);\n setIsUserFetchCompleted(true);\n };\n withValidation(sdk.me)().then(stopUserLoading, stopUserLoading);\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetchStarted: isUserFetchStarted.current,\n isUserFetchCompleted,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetchStarted: isSessionFetchStarted.current,\n isSessionFetchCompleted,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetchStarted.current,\n isUserFetchCompleted,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetchStarted.current,\n isSessionFetchCompleted,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["projectId","baseUrl","baseStaticUrl","baseCdnUrl","sessionTokenViaCookie","refreshTokenViaCookie","hooks","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","customStorage","children","user","setUser","useState","session","setSession","claims","setClaims","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isSessionFetchCompleted","setIsSessionFetchCompleted","isUserFetchCompleted","setIsUserFetchCompleted","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","unsubscribeClaims","onClaimsChange","isSessionFetchStarted","isUserFetchStarted","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","isDescopeBridge","stopSessionLoading","withValidation","refresh","undefined","then","fetchUser","stopUserLoading","me","value","useMemo","React","default","createElement","Context","Provider"],"mappings":"kQA8D6C,EAC3CA,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,yBAAwB,EACxBC,yBAAwB,EACxBC,QACAC,iBAAgB,EAChBC,eAAc,EACdC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,gBACAC,eAEA,MAAOC,EAAMC,GAAWC,EAAQA,YACzBC,EAASC,GAAcF,EAAQA,YAC/BG,EAAQC,GAAaJ,EAAQA,YAC7BK,EAAiBC,GAAsBN,EAAQA,UAAC,IAEhDO,EAAeC,GAAoBR,EAAQA,UAAC,IAC5CS,EAAkBC,GAAuBV,EAAQA,UAAC,IAGlDW,EAAeC,GAAoBZ,EAAAA,WAAWT,IAG9CsB,EAAyBC,GAA8Bd,EAAQA,UAAC,IAEhEe,EAAsBC,GAA2BhB,EAAQA,UAAC,GAC3DiB,EAAsBC,UAAO,GAE7BC,EAAMC,EAAAA,QAAO,CACjBtC,YACAC,UACAM,gBACAC,cACAJ,wBACAC,wBACAC,QACAG,aACAC,6BACAC,uCACAC,oBACAC,mBACAC,kBAGFyB,EAAAA,WAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBrB,GACnDsB,EAAkBL,EAAIM,aAAa1B,GACnC2B,EACJP,EAAIQ,wBAAwBrB,GACxBsB,EAAoBT,EAAIU,eAAezB,GAE7C,MAAO,KACLkB,IACAE,IACAE,IACAE,GAAmB,CAEtB,CACe,GACf,CAACT,IAEJ,MAAMW,EAAwBZ,UAAO,GAC/Ba,EAAqBb,UAAO,GAIlCG,EAAAA,WAAU,KACJF,GAAO5B,IAAe0B,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCvB,GAAiB,GAGjBkB,EAAsBE,SAAU,EAChClB,GAA2B,EAAK,IAEnC,GACA,IAEH,MAAMsB,EAAeC,EAAAA,aAAY,KAE/B,GAAIC,oBAAmB,OAGvB,GAAIR,EAAsBE,QAAS,OACnCF,EAAsBE,SAAU,EAEhCtB,GAAoB,GACpB,MAAM6B,EAAqB,KACzB7B,GAAoB,GACpBI,GAA2B,EAAK,EAOlC0B,EAAcA,eAACrB,eAAAA,EAAKsB,QAApBD,MAA6BE,GAAW,GAAMC,KAC5CJ,EACAA,EACD,GACA,CAACpB,IAEEyB,EAAYP,EAAAA,aAAY,KAE5B,GAAIN,EAAmBC,QAAS,OAChCD,EAAmBC,SAAU,EAE7BxB,GAAiB,GAGjB,MAAMqC,EAAkB,KACtBrC,GAAiB,GACjBQ,GAAwB,EAAK,EAE/BwB,EAAcA,eAACrB,EAAI2B,GAAnBN,GAAyBG,KAAKE,EAAiBA,EAAgB,GAC9D,CAAC1B,IAEE4B,EAAQC,EAAAA,SACZ,KAAO,CACLJ,YACA9C,OACAS,gBACAwB,mBAAoBA,EAAmBC,QACvCjB,uBACAqB,eACAnC,UACAI,kBACAI,mBACAE,gBACAmB,sBAAuBA,EAAsBE,QAC7CnB,0BACA/B,YACAC,UACAC,gBACAC,aACAO,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAgB,SAEF,CACEyB,EACA9C,EACAS,EACAwB,EAAmBC,QACnBjB,EACAqB,EACAnC,EACAI,EACAI,EACAE,EACAmB,EAAsBE,QACtBnB,EACA/B,EACAC,EACAC,EACAC,EACAQ,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAgB,IAGJ,OAAO8B,EAAAC,QAAAC,cAACC,UAAQC,SAAQ,CAACN,MAAOA,GAAQlD,EAA4B"}
@@ -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.3.17"};
1
+ "use strict";const e="undefined"!=typeof window;exports.IS_BROWSER=e,exports.baseHeaders={"x-descope-sdk-name":"react","x-descope-sdk-version":"3.3.19"};
2
2
  //# sourceMappingURL=constants.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("./useContext.js");exports.default=()=>{const{user:s,fetchUser:t,isUserLoading:u,isAuthenticated:c,isUserFetched:i}=r.default(),[o,n]=e.useState(!1),a=e.useRef(u),d=e.useMemo((()=>!s&&!u&&c&&!o),[t,c,o]);return e.useMemo((()=>{a.current=u}),[u]),e.useMemo((()=>{d&&!i&&(a.current=!0)}),[d,i]),e.useEffect((()=>{d&&(n(!0),t())}),[d]),{isUserLoading:a.current,user:s}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("./useContext.js");exports.default=()=>{const{user:r,fetchUser:s,isUserLoading:u,isAuthenticated:c,isUserFetchStarted:i,isUserFetchCompleted:o}=t.default(),[a,n]=e.useState(!1),d=e.useRef(u),f=e.useMemo((()=>!r&&!u&&c&&!a),[s,c,a]);return e.useMemo((()=>{d.current=u}),[u,o]),e.useMemo((()=>{f&&!i&&(d.current=!0)}),[f,i]),e.useEffect((()=>{f&&(n(!0),s())}),[f]),{isUserLoading:d.current,user:r}};
2
2
  //# sourceMappingURL=useUser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useUser.js","sources":["../../../src/hooks/useUser.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport useContext from './useContext';\n\nconst useUser = () => {\n const { user, fetchUser, isUserLoading, isAuthenticated, isUserFetched } =\n useContext();\n const [isInit, setIsInit] = useState(false); // we want to get the user only in the first time we got a session\n\n // when session should be received, we want the return value of \"isUserLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isUserLoading);\n\n const shouldFetchUser = useMemo(\n () => !user && !isUserLoading && isAuthenticated && !isInit,\n [fetchUser, isAuthenticated, isInit],\n );\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n isLoading.current = isUserLoading;\n }, [isUserLoading]);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchUser && !isUserFetched) {\n isLoading.current = true;\n }\n }, [shouldFetchUser, isUserFetched]);\n\n useEffect(() => {\n if (shouldFetchUser) {\n setIsInit(true);\n fetchUser();\n }\n }, [shouldFetchUser]);\n\n return { isUserLoading: isLoading.current, user };\n};\n\nexport default useUser;\n"],"names":["user","fetchUser","isUserLoading","isAuthenticated","isUserFetched","useContext","isInit","setIsInit","useState","isLoading","useRef","shouldFetchUser","useMemo","current","useEffect"],"mappings":"wIAGgB,KACd,MAAMA,KAAEA,EAAIC,UAAEA,EAASC,cAAEA,EAAaC,gBAAEA,EAAeC,cAAEA,GACvDC,EAAAA,WACKC,EAAQC,GAAaC,EAAQA,UAAC,GAI/BC,EAAYC,SAAOR,GAEnBS,EAAkBC,EAAOA,SAC7B,KAAOZ,IAASE,GAAiBC,IAAoBG,GACrD,CAACL,EAAWE,EAAiBG,IAsB/B,OAlBAM,EAAAA,SAAQ,KACNH,EAAUI,QAAUX,CAAa,GAChC,CAACA,IAGJU,EAAAA,SAAQ,KACFD,IAAoBP,IACtBK,EAAUI,SAAU,EACrB,GACA,CAACF,EAAiBP,IAErBU,EAAAA,WAAU,KACJH,IACFJ,GAAU,GACVN,IACD,GACA,CAACU,IAEG,CAAET,cAAeO,EAAUI,QAASb,OAAM"}
1
+ {"version":3,"file":"useUser.js","sources":["../../../src/hooks/useUser.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport useContext from './useContext';\n\nconst useUser = () => {\n const {\n user,\n fetchUser,\n isUserLoading,\n isAuthenticated,\n isUserFetchStarted,\n isUserFetchCompleted,\n } = useContext();\n const [isInit, setIsInit] = useState(false); // we want to get the user only in the first time we got a session\n\n // when session should be received, we want the return value of \"isUserLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isUserLoading);\n\n const shouldFetchUser = useMemo(\n () => !user && !isUserLoading && isAuthenticated && !isInit,\n [fetchUser, isAuthenticated, isInit],\n );\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n // isUserFetchCompleted guarantees a re-run when the fetch settles, even if isUserLoading never visibly changed\n useMemo(() => {\n isLoading.current = isUserLoading;\n }, [isUserLoading, isUserFetchCompleted]);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchUser && !isUserFetchStarted) {\n isLoading.current = true;\n }\n }, [shouldFetchUser, isUserFetchStarted]);\n\n useEffect(() => {\n if (shouldFetchUser) {\n setIsInit(true);\n fetchUser();\n }\n }, [shouldFetchUser]);\n\n return { isUserLoading: isLoading.current, user };\n};\n\nexport default useUser;\n"],"names":["user","fetchUser","isUserLoading","isAuthenticated","isUserFetchStarted","isUserFetchCompleted","useContext","isInit","setIsInit","useState","isLoading","useRef","shouldFetchUser","useMemo","current","useEffect"],"mappings":"wIAGgB,KACd,MAAMA,KACJA,EAAIC,UACJA,EAASC,cACTA,EAAaC,gBACbA,EAAeC,mBACfA,EAAkBC,qBAClBA,GACEC,EAAAA,WACGC,EAAQC,GAAaC,EAAQA,UAAC,GAI/BC,EAAYC,SAAOT,GAEnBU,EAAkBC,EAAOA,SAC7B,KAAOb,IAASE,GAAiBC,IAAoBI,GACrD,CAACN,EAAWE,EAAiBI,IAuB/B,OAlBAM,EAAAA,SAAQ,KACNH,EAAUI,QAAUZ,CAAa,GAChC,CAACA,EAAeG,IAGnBQ,EAAAA,SAAQ,KACFD,IAAoBR,IACtBM,EAAUI,SAAU,EACrB,GACA,CAACF,EAAiBR,IAErBW,EAAAA,WAAU,KACJH,IACFJ,GAAU,GACVP,IACD,GACA,CAACW,IAEG,CAAEV,cAAeQ,EAAUI,QAASd,OAAM"}
@@ -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{isDescopeBridge as a,withValidation as c}from"../../utils.js";import u from"./useSdk.js";const h=({projectId:h,baseUrl:d="",baseStaticUrl:f="",baseCdnUrl:k="",sessionTokenViaCookie:l=!1,refreshTokenViaCookie:m=!1,hooks:g,persistTokens:C=!0,autoRefresh:U=!0,oidcConfig:p,storeLastAuthenticatedUser:L=!0,keepLastAuthenticatedUserAfterLogout:S=!1,refreshCookieName:A="",getExternalToken:T,customStorage:b,children:j})=>{const[I,v]=t(),[x,N]=t(),[V,E]=t(),[F,R]=t(!1),[y,O]=t(!1),[P,q]=t(!1),[w,z]=t(!!p),[B,D]=t(!1),G=s(!1),H=u({projectId:h,baseUrl:d,persistTokens:C,autoRefresh:U,sessionTokenViaCookie:l,refreshTokenViaCookie:m,hooks:g,oidcConfig:p,storeLastAuthenticatedUser:L,keepLastAuthenticatedUserAfterLogout:S,refreshCookieName:A,getExternalToken:T,customStorage:b});r((()=>{if(H){const e=H.onSessionTokenChange(N),t=H.onUserChange(v),s=H.onIsAuthenticatedChange(R),r=H.onClaimsChange(E);return()=>{e(),t(),s(),r()}}}),[H]);const J=s(!1),K=s(!1);r((()=>{H&&p&&!G.current&&(G.current=!0,H.oidc.finishLoginIfNeed().finally((()=>{z(!1),J.current=!0,D(!0)})))}),[]);const M=o((()=>{if(a())return;if(J.current)return;J.current=!0,q(!0);const e=()=>{q(!1),D(!0)};c(null==H?void 0:H.refresh)(void 0,!0).then(e,e)}),[H]),Q=o((()=>{if(K.current)return;K.current=!0,O(!0);const e=()=>O(!1);c(H.me)().then(e,e)}),[H]),W=n((()=>({fetchUser:Q,user:I,isUserLoading:y,isUserFetched:K.current,fetchSession:M,session:x,isAuthenticated:F,isSessionLoading:P,isOidcLoading:w,isSessionFetchStarted:J.current,isSessionFetchCompleted:B,projectId:h,baseUrl:d,baseStaticUrl:f,baseCdnUrl:k,storeLastAuthenticatedUser:L,keepLastAuthenticatedUserAfterLogout:S,refreshCookieName:A,customStorage:b,setUser:v,setSession:N,setIsAuthenticated:R,claims:V,sdk:H})),[Q,I,y,K.current,M,x,F,P,w,J.current,B,h,d,f,k,S,A,b,v,N,R,V,H]);return e.createElement(i.Provider,{value:W},j)};export{h 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{isDescopeBridge as a,withValidation as c}from"../../utils.js";import u from"./useSdk.js";const h=({projectId:h,baseUrl:d="",baseStaticUrl:f="",baseCdnUrl:k="",sessionTokenViaCookie:l=!1,refreshTokenViaCookie:m=!1,hooks:C,persistTokens:U=!0,autoRefresh:g=!0,oidcConfig:p,storeLastAuthenticatedUser:S=!0,keepLastAuthenticatedUserAfterLogout:L=!1,refreshCookieName:A="",getExternalToken:T,customStorage:b,children:j})=>{const[I,v]=t(),[x,F]=t(),[N,V]=t(),[E,R]=t(!1),[y,O]=t(!1),[P,q]=t(!1),[w,z]=t(!!p),[B,D]=t(!1),[G,H]=t(!1),J=s(!1),K=u({projectId:h,baseUrl:d,persistTokens:U,autoRefresh:g,sessionTokenViaCookie:l,refreshTokenViaCookie:m,hooks:C,oidcConfig:p,storeLastAuthenticatedUser:S,keepLastAuthenticatedUserAfterLogout:L,refreshCookieName:A,getExternalToken:T,customStorage:b});r((()=>{if(K){const e=K.onSessionTokenChange(F),t=K.onUserChange(v),s=K.onIsAuthenticatedChange(R),r=K.onClaimsChange(V);return()=>{e(),t(),s(),r()}}}),[K]);const M=s(!1),Q=s(!1);r((()=>{K&&p&&!J.current&&(J.current=!0,K.oidc.finishLoginIfNeed().finally((()=>{z(!1),M.current=!0,D(!0)})))}),[]);const W=o((()=>{if(a())return;if(M.current)return;M.current=!0,q(!0);const e=()=>{q(!1),D(!0)};c(null==K?void 0:K.refresh)(void 0,!0).then(e,e)}),[K]),X=o((()=>{if(Q.current)return;Q.current=!0,O(!0);const e=()=>{O(!1),H(!0)};c(K.me)().then(e,e)}),[K]),Y=n((()=>({fetchUser:X,user:I,isUserLoading:y,isUserFetchStarted:Q.current,isUserFetchCompleted:G,fetchSession:W,session:x,isAuthenticated:E,isSessionLoading:P,isOidcLoading:w,isSessionFetchStarted:M.current,isSessionFetchCompleted:B,projectId:h,baseUrl:d,baseStaticUrl:f,baseCdnUrl:k,storeLastAuthenticatedUser:S,keepLastAuthenticatedUserAfterLogout:L,refreshCookieName:A,customStorage:b,setUser:v,setSession:F,setIsAuthenticated:R,claims:N,sdk:K})),[X,I,y,Q.current,G,W,x,E,P,w,M.current,B,h,d,f,k,L,A,b,v,F,R,N,K]);return e.createElement(i.Provider,{value:Y},j)};export{h 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 {\n CookieConfig,\n OidcConfig,\n AutoRefreshConfig,\n} from '@descope/web-js-sdk';\nimport { Claims } from '@descope/core-js-sdk';\nimport { CustomStorage } from '@descope/web-component';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { isDescopeBridge, withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ntype Hooks = Parameters<typeof useSdk>[0]['hooks'];\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 // allows to override the base URL that is used to fetch external script files\n baseCdnUrl?: string;\n // Default is true. If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // Default is true. If true, the SDK will automatically refresh the session token when it is about to expire.\n // Pass `{ customActivityTracking: true }` to skip refresh for idle users — you must call `sdk.markUserActive()` to signal activity.\n autoRefresh?: AutoRefreshConfig;\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 true, refresh token will be stored on cookie. Otherwise, the refresh token will be\n // stored on local storage and can be accessed with getRefreshToken function\n // Use this option if you need server-side access to the refresh token (e.g., in Next.js middleware)\n // to enable refreshing sessions on the server before they expire\n refreshTokenViaCookie?: CookieConfig;\n hooks?: Hooks;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // Default is true. 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 // Custom storage object for authentication related data\n customStorage?: CustomStorage;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n refreshTokenViaCookie = false,\n hooks = undefined,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n customStorage = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [claims, setClaims] = useState<Claims>();\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 // flips once when the first session fetch settles - unlike isSessionLoading, this change\n // can't be lost if React batches the loading true/false updates into a single render\n const [isSessionFetchCompleted, setIsSessionFetchCompleted] = useState(false);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n autoRefresh,\n sessionTokenViaCookie,\n refreshTokenViaCookie,\n hooks,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\n customStorage,\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 const unsubscribeClaims = sdk.onClaimsChange(setClaims);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n unsubscribeClaims();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetchStarted = 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 // finishing the OIDC login already fetched the session, so mark the fetch as both\n // started (fetchSession won't run again) and completed, even though it never ran\n isSessionFetchStarted.current = true;\n setIsSessionFetchCompleted(true);\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // Don't load the session in native flows, though we'd usually not get here at all from useSession in this case\n if (isDescopeBridge()) return;\n\n // We want that the session will fetched only once\n if (isSessionFetchStarted.current) return;\n isSessionFetchStarted.current = true;\n\n setIsSessionLoading(true);\n const stopSessionLoading = () => {\n setIsSessionLoading(false);\n setIsSessionFetchCompleted(true);\n };\n // Clear the loading state on both fulfilment and rejection. A rejected\n // refresh (e.g. a transient network failure on the proactive refresh) must\n // still clear `isSessionLoading` - `isSessionFetchStarted` is already set so\n // `fetchSession` never re-runs, and consumers (e.g. useSession) would\n // otherwise hang on \"loading\" forever despite a valid session.\n withValidation(sdk?.refresh)(undefined, true).then(\n stopSessionLoading,\n stopSessionLoading,\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 // Clear the loading state on both fulfilment and rejection so a failed\n // `me()` doesn't leave `isUserLoading` stuck `true` (see fetchSession).\n const stopUserLoading = () => setIsUserLoading(false);\n withValidation(sdk.me)().then(stopUserLoading, stopUserLoading);\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 isSessionFetchStarted: isSessionFetchStarted.current,\n isSessionFetchCompleted,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetchStarted.current,\n isSessionFetchCompleted,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["AuthProvider","projectId","baseUrl","baseStaticUrl","baseCdnUrl","sessionTokenViaCookie","refreshTokenViaCookie","hooks","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","customStorage","children","user","setUser","useState","session","setSession","claims","setClaims","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isSessionFetchCompleted","setIsSessionFetchCompleted","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","unsubscribeClaims","onClaimsChange","isSessionFetchStarted","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","isDescopeBridge","stopSessionLoading","withValidation","refresh","undefined","then","fetchUser","stopUserLoading","me","value","useMemo","React","createElement","Context","Provider"],"mappings":"mOA8DA,MAAMA,EAAuC,EAC3CC,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,yBAAwB,EACxBC,yBAAwB,EACxBC,QACAC,iBAAgB,EAChBC,eAAc,EACdC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,gBACAC,eAEA,MAAOC,EAAMC,GAAWC,KACjBC,EAASC,GAAcF,KACvBG,EAAQC,GAAaJ,KACrBK,EAAiBC,GAAsBN,GAAS,IAEhDO,EAAeC,GAAoBR,GAAS,IAC5CS,EAAkBC,GAAuBV,GAAS,IAGlDW,EAAeC,GAAoBZ,IAAWT,IAG9CsB,EAAyBC,GAA8Bd,GAAS,GACjEe,EAAsBC,GAAO,GAE7BC,EAAMC,EAAO,CACjBpC,YACAC,UACAM,gBACAC,cACAJ,wBACAC,wBACAC,QACAG,aACAC,6BACAC,uCACAC,oBACAC,mBACAC,kBAGFuB,GAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBnB,GACnDoB,EAAkBL,EAAIM,aAAaxB,GACnCyB,EACJP,EAAIQ,wBAAwBnB,GACxBoB,EAAoBT,EAAIU,eAAevB,GAE7C,MAAO,KACLgB,IACAE,IACAE,IACAE,GAAmB,CAEtB,CACe,GACf,CAACT,IAEJ,MAAMW,EAAwBZ,GAAO,GAC/Ba,EAAgBb,GAAO,GAI7BG,GAAU,KACJF,GAAO1B,IAAewB,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCrB,GAAiB,GAGjBgB,EAAsBE,SAAU,EAChChB,GAA2B,EAAK,IAEnC,GACA,IAEH,MAAMoB,EAAeC,GAAY,KAE/B,GAAIC,IAAmB,OAGvB,GAAIR,EAAsBE,QAAS,OACnCF,EAAsBE,SAAU,EAEhCpB,GAAoB,GACpB,MAAM2B,EAAqB,KACzB3B,GAAoB,GACpBI,GAA2B,EAAK,EAOlCwB,EAAerB,eAAAA,EAAKsB,QAApBD,MAA6BE,GAAW,GAAMC,KAC5CJ,EACAA,EACD,GACA,CAACpB,IAEEyB,EAAYP,GAAY,KAE5B,GAAIN,EAAcC,QAAS,OAC3BD,EAAcC,SAAU,EAExBtB,GAAiB,GAGjB,MAAMmC,EAAkB,IAAMnC,GAAiB,GAC/C8B,EAAerB,EAAI2B,GAAnBN,GAAyBG,KAAKE,EAAiBA,EAAgB,GAC9D,CAAC1B,IAEE4B,EAAQC,GACZ,KAAO,CACLJ,YACA5C,OACAS,gBACAsB,cAAeA,EAAcC,QAC7BI,eACAjC,UACAI,kBACAI,mBACAE,gBACAiB,sBAAuBA,EAAsBE,QAC7CjB,0BACA/B,YACAC,UACAC,gBACAC,aACAO,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAc,SAEF,CACEyB,EACA5C,EACAS,EACAsB,EAAcC,QACdI,EACAjC,EACAI,EACAI,EACAE,EACAiB,EAAsBE,QACtBjB,EACA/B,EACAC,EACAC,EACAC,EACAQ,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAc,IAGJ,OAAO8B,EAAAC,cAACC,EAAQC,SAAQ,CAACL,MAAOA,GAAQhD,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 {\n CookieConfig,\n OidcConfig,\n AutoRefreshConfig,\n} from '@descope/web-js-sdk';\nimport { Claims } from '@descope/core-js-sdk';\nimport { CustomStorage } from '@descope/web-component';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { isDescopeBridge, withValidation } from '../../utils';\nimport useSdk from './useSdk';\n\ntype Hooks = Parameters<typeof useSdk>[0]['hooks'];\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 // allows to override the base URL that is used to fetch external script files\n baseCdnUrl?: string;\n // Default is true. If true, tokens will be stored on local storage and can accessed with getToken function\n persistTokens?: boolean;\n // Default is true. If true, the SDK will automatically refresh the session token when it is about to expire.\n // Pass `{ customActivityTracking: true }` to skip refresh for idle users — you must call `sdk.markUserActive()` to signal activity.\n autoRefresh?: AutoRefreshConfig;\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 true, refresh token will be stored on cookie. Otherwise, the refresh token will be\n // stored on local storage and can be accessed with getRefreshToken function\n // Use this option if you need server-side access to the refresh token (e.g., in Next.js middleware)\n // to enable refreshing sessions on the server before they expire\n refreshTokenViaCookie?: CookieConfig;\n hooks?: Hooks;\n // If truthy he SDK refresh and logout functions will use the OIDC client\n // Accepts boolean or OIDC configuration\n oidcConfig?: OidcConfig;\n // Default is true. 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 // Custom storage object for authentication related data\n customStorage?: CustomStorage;\n children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n refreshTokenViaCookie = false,\n hooks = undefined,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n customStorage = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\n const [claims, setClaims] = useState<Claims>();\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 // flips once when the first session fetch settles - unlike isSessionLoading, this change\n // can't be lost if React batches the loading true/false updates into a single render\n const [isSessionFetchCompleted, setIsSessionFetchCompleted] = useState(false);\n // same as isSessionFetchCompleted, for the user fetch\n const [isUserFetchCompleted, setIsUserFetchCompleted] = useState(false);\n const isOidcFinishedLogin = useRef(false);\n\n const sdk = useSdk({\n projectId,\n baseUrl,\n persistTokens,\n autoRefresh,\n sessionTokenViaCookie,\n refreshTokenViaCookie,\n hooks,\n oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\n customStorage,\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 const unsubscribeClaims = sdk.onClaimsChange(setClaims);\n\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\n unsubscribeClaims();\n };\n }\n return undefined;\n }, [sdk]);\n\n const isSessionFetchStarted = useRef(false);\n const isUserFetchStarted = 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 // finishing the OIDC login already fetched the session, so mark the fetch as both\n // started (fetchSession won't run again) and completed, even though it never ran\n isSessionFetchStarted.current = true;\n setIsSessionFetchCompleted(true);\n });\n }\n }, []);\n\n const fetchSession = useCallback(() => {\n // Don't load the session in native flows, though we'd usually not get here at all from useSession in this case\n if (isDescopeBridge()) return;\n\n // We want that the session will fetched only once\n if (isSessionFetchStarted.current) return;\n isSessionFetchStarted.current = true;\n\n setIsSessionLoading(true);\n const stopSessionLoading = () => {\n setIsSessionLoading(false);\n setIsSessionFetchCompleted(true);\n };\n // Clear the loading state on both fulfilment and rejection. A rejected\n // refresh (e.g. a transient network failure on the proactive refresh) must\n // still clear `isSessionLoading` - `isSessionFetchStarted` is already set so\n // `fetchSession` never re-runs, and consumers (e.g. useSession) would\n // otherwise hang on \"loading\" forever despite a valid session.\n withValidation(sdk?.refresh)(undefined, true).then(\n stopSessionLoading,\n stopSessionLoading,\n );\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetchStarted.current) return;\n isUserFetchStarted.current = true;\n\n setIsUserLoading(true);\n // Clear the loading state on both fulfilment and rejection so a failed\n // `me()` doesn't leave `isUserLoading` stuck `true` (see fetchSession).\n const stopUserLoading = () => {\n setIsUserLoading(false);\n setIsUserFetchCompleted(true);\n };\n withValidation(sdk.me)().then(stopUserLoading, stopUserLoading);\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetchStarted: isUserFetchStarted.current,\n isUserFetchCompleted,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetchStarted: isSessionFetchStarted.current,\n isSessionFetchCompleted,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n }),\n [\n fetchUser,\n user,\n isUserLoading,\n isUserFetchStarted.current,\n isUserFetchCompleted,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetchStarted.current,\n isSessionFetchCompleted,\n projectId,\n baseUrl,\n baseStaticUrl,\n baseCdnUrl,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n customStorage,\n setUser,\n setSession,\n setIsAuthenticated,\n claims,\n sdk,\n ],\n );\n return <Context.Provider value={value}>{children}</Context.Provider>;\n};\n\nexport default AuthProvider;\n"],"names":["AuthProvider","projectId","baseUrl","baseStaticUrl","baseCdnUrl","sessionTokenViaCookie","refreshTokenViaCookie","hooks","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","customStorage","children","user","setUser","useState","session","setSession","claims","setClaims","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isSessionFetchCompleted","setIsSessionFetchCompleted","isUserFetchCompleted","setIsUserFetchCompleted","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","unsubscribeClaims","onClaimsChange","isSessionFetchStarted","isUserFetchStarted","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","isDescopeBridge","stopSessionLoading","withValidation","refresh","undefined","then","fetchUser","stopUserLoading","me","value","useMemo","React","createElement","Context","Provider"],"mappings":"mOA8DA,MAAMA,EAAuC,EAC3CC,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,yBAAwB,EACxBC,yBAAwB,EACxBC,QACAC,iBAAgB,EAChBC,eAAc,EACdC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,gBACAC,eAEA,MAAOC,EAAMC,GAAWC,KACjBC,EAASC,GAAcF,KACvBG,EAAQC,GAAaJ,KACrBK,EAAiBC,GAAsBN,GAAS,IAEhDO,EAAeC,GAAoBR,GAAS,IAC5CS,EAAkBC,GAAuBV,GAAS,IAGlDW,EAAeC,GAAoBZ,IAAWT,IAG9CsB,EAAyBC,GAA8Bd,GAAS,IAEhEe,EAAsBC,GAA2BhB,GAAS,GAC3DiB,EAAsBC,GAAO,GAE7BC,EAAMC,EAAO,CACjBtC,YACAC,UACAM,gBACAC,cACAJ,wBACAC,wBACAC,QACAG,aACAC,6BACAC,uCACAC,oBACAC,mBACAC,kBAGFyB,GAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBrB,GACnDsB,EAAkBL,EAAIM,aAAa1B,GACnC2B,EACJP,EAAIQ,wBAAwBrB,GACxBsB,EAAoBT,EAAIU,eAAezB,GAE7C,MAAO,KACLkB,IACAE,IACAE,IACAE,GAAmB,CAEtB,CACe,GACf,CAACT,IAEJ,MAAMW,EAAwBZ,GAAO,GAC/Ba,EAAqBb,GAAO,GAIlCG,GAAU,KACJF,GAAO5B,IAAe0B,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCvB,GAAiB,GAGjBkB,EAAsBE,SAAU,EAChClB,GAA2B,EAAK,IAEnC,GACA,IAEH,MAAMsB,EAAeC,GAAY,KAE/B,GAAIC,IAAmB,OAGvB,GAAIR,EAAsBE,QAAS,OACnCF,EAAsBE,SAAU,EAEhCtB,GAAoB,GACpB,MAAM6B,EAAqB,KACzB7B,GAAoB,GACpBI,GAA2B,EAAK,EAOlC0B,EAAerB,eAAAA,EAAKsB,QAApBD,MAA6BE,GAAW,GAAMC,KAC5CJ,EACAA,EACD,GACA,CAACpB,IAEEyB,EAAYP,GAAY,KAE5B,GAAIN,EAAmBC,QAAS,OAChCD,EAAmBC,SAAU,EAE7BxB,GAAiB,GAGjB,MAAMqC,EAAkB,KACtBrC,GAAiB,GACjBQ,GAAwB,EAAK,EAE/BwB,EAAerB,EAAI2B,GAAnBN,GAAyBG,KAAKE,EAAiBA,EAAgB,GAC9D,CAAC1B,IAEE4B,EAAQC,GACZ,KAAO,CACLJ,YACA9C,OACAS,gBACAwB,mBAAoBA,EAAmBC,QACvCjB,uBACAqB,eACAnC,UACAI,kBACAI,mBACAE,gBACAmB,sBAAuBA,EAAsBE,QAC7CnB,0BACA/B,YACAC,UACAC,gBACAC,aACAO,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAgB,SAEF,CACEyB,EACA9C,EACAS,EACAwB,EAAmBC,QACnBjB,EACAqB,EACAnC,EACAI,EACAI,EACAE,EACAmB,EAAsBE,QACtBnB,EACA/B,EACAC,EACAC,EACAC,EACAQ,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAgB,IAGJ,OAAO8B,EAAAC,cAACC,EAAQC,SAAQ,CAACL,MAAOA,GAAQlD,EAA4B"}
@@ -1,2 +1,2 @@
1
- const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"3.3.17"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
1
+ const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"3.3.19"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
2
2
  //# sourceMappingURL=constants.js.map
@@ -1,2 +1,2 @@
1
- import{useState as e,useRef as r,useMemo as t,useEffect as s}from"react";import n from"./useContext.js";const o=()=>{const{user:o,fetchUser:c,isUserLoading:i,isAuthenticated:u,isUserFetched:a}=n(),[d,f]=e(!1),m=r(i),U=t((()=>!o&&!i&&u&&!d),[c,u,d]);return t((()=>{m.current=i}),[i]),t((()=>{U&&!a&&(m.current=!0)}),[U,a]),s((()=>{U&&(f(!0),c())}),[U]),{isUserLoading:m.current,user:o}};export{o as default};
1
+ import{useState as e,useRef as r,useMemo as t,useEffect as s}from"react";import o from"./useContext.js";const c=()=>{const{user:c,fetchUser:i,isUserLoading:n,isAuthenticated:u,isUserFetchStarted:a,isUserFetchCompleted:d}=o(),[m,U]=e(!1),f=r(n),h=t((()=>!c&&!n&&u&&!m),[i,u,m]);return t((()=>{f.current=n}),[n,d]),t((()=>{h&&!a&&(f.current=!0)}),[h,a]),s((()=>{h&&(U(!0),i())}),[h]),{isUserLoading:f.current,user:c}};export{c as default};
2
2
  //# sourceMappingURL=useUser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useUser.js","sources":["../../../src/hooks/useUser.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport useContext from './useContext';\n\nconst useUser = () => {\n const { user, fetchUser, isUserLoading, isAuthenticated, isUserFetched } =\n useContext();\n const [isInit, setIsInit] = useState(false); // we want to get the user only in the first time we got a session\n\n // when session should be received, we want the return value of \"isUserLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isUserLoading);\n\n const shouldFetchUser = useMemo(\n () => !user && !isUserLoading && isAuthenticated && !isInit,\n [fetchUser, isAuthenticated, isInit],\n );\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n isLoading.current = isUserLoading;\n }, [isUserLoading]);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchUser && !isUserFetched) {\n isLoading.current = true;\n }\n }, [shouldFetchUser, isUserFetched]);\n\n useEffect(() => {\n if (shouldFetchUser) {\n setIsInit(true);\n fetchUser();\n }\n }, [shouldFetchUser]);\n\n return { isUserLoading: isLoading.current, user };\n};\n\nexport default useUser;\n"],"names":["useUser","user","fetchUser","isUserLoading","isAuthenticated","isUserFetched","useContext","isInit","setIsInit","useState","isLoading","useRef","shouldFetchUser","useMemo","current","useEffect"],"mappings":"wGAGM,MAAAA,EAAU,KACd,MAAMC,KAAEA,EAAIC,UAAEA,EAASC,cAAEA,EAAaC,gBAAEA,EAAeC,cAAEA,GACvDC,KACKC,EAAQC,GAAaC,GAAS,GAI/BC,EAAYC,EAAOR,GAEnBS,EAAkBC,GACtB,KAAOZ,IAASE,GAAiBC,IAAoBG,GACrD,CAACL,EAAWE,EAAiBG,IAsB/B,OAlBAM,GAAQ,KACNH,EAAUI,QAAUX,CAAa,GAChC,CAACA,IAGJU,GAAQ,KACFD,IAAoBP,IACtBK,EAAUI,SAAU,EACrB,GACA,CAACF,EAAiBP,IAErBU,GAAU,KACJH,IACFJ,GAAU,GACVN,IACD,GACA,CAACU,IAEG,CAAET,cAAeO,EAAUI,QAASb,OAAM"}
1
+ {"version":3,"file":"useUser.js","sources":["../../../src/hooks/useUser.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport useContext from './useContext';\n\nconst useUser = () => {\n const {\n user,\n fetchUser,\n isUserLoading,\n isAuthenticated,\n isUserFetchStarted,\n isUserFetchCompleted,\n } = useContext();\n const [isInit, setIsInit] = useState(false); // we want to get the user only in the first time we got a session\n\n // when session should be received, we want the return value of \"isUserLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isUserLoading);\n\n const shouldFetchUser = useMemo(\n () => !user && !isUserLoading && isAuthenticated && !isInit,\n [fetchUser, isAuthenticated, isInit],\n );\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n // isUserFetchCompleted guarantees a re-run when the fetch settles, even if isUserLoading never visibly changed\n useMemo(() => {\n isLoading.current = isUserLoading;\n }, [isUserLoading, isUserFetchCompleted]);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchUser && !isUserFetchStarted) {\n isLoading.current = true;\n }\n }, [shouldFetchUser, isUserFetchStarted]);\n\n useEffect(() => {\n if (shouldFetchUser) {\n setIsInit(true);\n fetchUser();\n }\n }, [shouldFetchUser]);\n\n return { isUserLoading: isLoading.current, user };\n};\n\nexport default useUser;\n"],"names":["useUser","user","fetchUser","isUserLoading","isAuthenticated","isUserFetchStarted","isUserFetchCompleted","useContext","isInit","setIsInit","useState","isLoading","useRef","shouldFetchUser","useMemo","current","useEffect"],"mappings":"wGAGM,MAAAA,EAAU,KACd,MAAMC,KACJA,EAAIC,UACJA,EAASC,cACTA,EAAaC,gBACbA,EAAeC,mBACfA,EAAkBC,qBAClBA,GACEC,KACGC,EAAQC,GAAaC,GAAS,GAI/BC,EAAYC,EAAOT,GAEnBU,EAAkBC,GACtB,KAAOb,IAASE,GAAiBC,IAAoBI,GACrD,CAACN,EAAWE,EAAiBI,IAuB/B,OAlBAM,GAAQ,KACNH,EAAUI,QAAUZ,CAAa,GAChC,CAACA,EAAeG,IAGnBQ,GAAQ,KACFD,IAAoBR,IACtBM,EAAUI,SAAU,EACrB,GACA,CAACF,EAAiBR,IAErBW,GAAU,KACJH,IACFJ,GAAU,GACVP,IACD,GACA,CAACW,IAEG,CAAEV,cAAeQ,EAAUI,QAASd,OAAM"}