@descope/react-sdk 3.3.11 → 3.3.13

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:g=!0,keepLastAuthenticatedUserAfterLogout:C=!1,refreshCookieName:S="",getExternalToken:U,customStorage:m,children:A})=>{const[L,p]=e.useState(),[b,T]=e.useState(),[j,v]=e.useState(),[I,V]=e.useState(!1),[q,x]=e.useState(!1),[E,R]=e.useState(!1),[N,_]=e.useState(!!k),F=e.useRef(!1),M=r.default({projectId:o,baseUrl:i,persistTokens:h,autoRefresh:l,sessionTokenViaCookie:c,refreshTokenViaCookie:d,hooks:f,oidcConfig:k,storeLastAuthenticatedUser:g,keepLastAuthenticatedUserAfterLogout:C,refreshCookieName:S,getExternalToken:U,customStorage:m});e.useEffect((()=>{if(M){const e=M.onSessionTokenChange(T),t=M.onUserChange(p),s=M.onIsAuthenticatedChange(V),r=M.onClaimsChange(v);return()=>{e(),t(),s(),r()}}}),[M]);const w=e.useRef(!1),y=e.useRef(!1);e.useEffect((()=>{M&&k&&!F.current&&(F.current=!0,M.oidc.finishLoginIfNeed().finally((()=>{_(!1),w.current=!0})))}),[]);const O=e.useCallback((()=>{if(s.isDescopeBridge())return;if(w.current)return;w.current=!0,R(!0);const e=()=>{requestAnimationFrame((()=>{setTimeout((()=>{R(!1)}),0)}))};s.withValidation(null==M?void 0:M.refresh)(void 0,!0).then(e,e)}),[M]),P=e.useCallback((()=>{if(y.current)return;y.current=!0,x(!0);const e=()=>x(!1);s.withValidation(M.me)().then(e,e)}),[M]),B=e.useMemo((()=>({fetchUser:P,user:L,isUserLoading:q,isUserFetched:y.current,fetchSession:O,session:b,isAuthenticated:I,isSessionLoading:E,isOidcLoading:N,isSessionFetched:w.current,projectId:o,baseUrl:i,baseStaticUrl:a,baseCdnUrl:u,storeLastAuthenticatedUser:g,keepLastAuthenticatedUserAfterLogout:C,refreshCookieName:S,customStorage:m,setUser:p,setSession:T,setIsAuthenticated:V,claims:j,sdk:M})),[P,L,q,y.current,O,b,I,E,N,w.current,o,i,a,u,C,S,m,p,T,V,j,M]);return n.default.createElement(t.default.Provider,{value:B},A)};
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)};
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 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 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 // 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 (isSessionFetched.current) return;\n isSessionFetched.current = true;\n\n setIsSessionLoading(true);\n const stopSessionLoading = () => {\n // Defer to a separate render pass so React doesn't batch this with\n // the setIsSessionLoading(true) above when refresh() short-circuits\n // synchronously - downstream consumers (e.g. useSession) need to\n // observe the false→true→false loading transition (#1393)\n requestAnimationFrame(() => {\n setTimeout(() => {\n setIsSessionLoading(false);\n }, 0);\n });\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` - `isSessionFetched` 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 isSessionFetched: isSessionFetched.current,\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 isSessionFetched.current,\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","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","unsubscribeClaims","onClaimsChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","isDescopeBridge","stopSessionLoading","requestAnimationFrame","setTimeout","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,GAC/CsB,EAAsBC,UAAO,GAE7BC,EAAMC,EAAAA,QAAO,CACjBlC,YACAC,UACAM,gBACAC,cACAJ,wBACAC,wBACAC,QACAG,aACAC,6BACAC,uCACAC,oBACAC,mBACAC,kBAGFqB,EAAAA,WAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBjB,GACnDkB,EAAkBL,EAAIM,aAAatB,GACnCuB,EACJP,EAAIQ,wBAAwBjB,GACxBkB,EAAoBT,EAAIU,eAAerB,GAE7C,MAAO,KACLc,IACAE,IACAE,IACAE,GAAmB,CAEtB,CACe,GACf,CAACT,IAEJ,MAAMW,EAAmBZ,UAAO,GAC1Ba,EAAgBb,UAAO,GAI7BG,EAAAA,WAAU,KACJF,GAAOxB,IAAesB,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCnB,GAAiB,GAEjBc,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,EAAAA,aAAY,KAE/B,GAAIC,oBAAmB,OAGvB,GAAIR,EAAiBE,QAAS,OAC9BF,EAAiBE,SAAU,EAE3BlB,GAAoB,GACpB,MAAMyB,EAAqB,KAKzBC,uBAAsB,KACpBC,YAAW,KACT3B,GAAoB,EAAM,GACzB,EAAE,GACL,EAOJ4B,EAAcA,eAACvB,eAAAA,EAAKwB,QAApBD,MAA6BE,GAAW,GAAMC,KAC5CN,EACAA,EACD,GACA,CAACpB,IAEE2B,EAAYT,EAAAA,aAAY,KAE5B,GAAIN,EAAcC,QAAS,OAC3BD,EAAcC,SAAU,EAExBpB,GAAiB,GAGjB,MAAMmC,EAAkB,IAAMnC,GAAiB,GAC/C8B,EAAcA,eAACvB,EAAI6B,GAAnBN,GAAyBG,KAAKE,EAAiBA,EAAgB,GAC9D,CAAC5B,IAEE8B,EAAQC,EAAAA,SACZ,KAAO,CACLJ,YACA5C,OACAS,gBACAoB,cAAeA,EAAcC,QAC7BI,eACA/B,UACAI,kBACAI,mBACAE,gBACAe,iBAAkBA,EAAiBE,QACnC9C,YACAC,UACAC,gBACAC,aACAO,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAY,SAEF,CACE2B,EACA5C,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB9C,EACAC,EACAC,EACAC,EACAQ,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAOgC,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 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,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.11"};
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.13"};
2
2
  //# sourceMappingURL=constants.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),s=require("./useContext.js"),i=require("../utils.js");exports.default=()=>{const{session:t,claims:r,isSessionLoading:n,isOidcLoading:o,fetchSession:u,isSessionFetched:c,isAuthenticated:a}=s.default(),d=e.useRef(n||o);e.useMemo((()=>{d.current=n||o}),[n,o]);const f=!a&&!n&&!i.isDescopeBridge();return e.useMemo((()=>{f&&!c&&(d.current=!0)}),[c]),e.useEffect((()=>{f&&u()}),[u]),{isSessionLoading:d.current,sessionToken:t,claims:r,isAuthenticated:a}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),s=require("./useContext.js"),t=require("../utils.js");exports.default=()=>{const{session:i,claims:r,isSessionLoading:o,isOidcLoading:n,fetchSession:u,isSessionFetchStarted:c,isSessionFetchCompleted:a,isAuthenticated:d}=s.default(),l=e.useRef(o||n);e.useMemo((()=>{l.current=o||n}),[o,n,a]);const f=!d&&!o&&!t.isDescopeBridge();return e.useMemo((()=>{f&&!c&&(l.current=!0)}),[c]),e.useEffect((()=>{f&&u()}),[u]),{isSessionLoading:l.current,sessionToken:i,claims:r,isAuthenticated:d}};
2
2
  //# sourceMappingURL=useSession.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSession.js","sources":["../../../src/hooks/useSession.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport useContext from './useContext';\nimport { isDescopeBridge } from '../utils';\n\nconst useSession = () => {\n const {\n session,\n claims,\n isSessionLoading,\n isOidcLoading,\n fetchSession,\n isSessionFetched,\n isAuthenticated,\n } = useContext();\n\n // when session should be received, we want the return value of \"isSessionLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isSessionLoading || isOidcLoading);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n isLoading.current = isSessionLoading || isOidcLoading;\n }, [isSessionLoading, isOidcLoading]);\n\n // In case we're in a native flow, we won't refresh the session anyway, so no point in marking the state as loading\n const shouldFetchSession = !isAuthenticated && !isSessionLoading && !isDescopeBridge();\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchSession && !isSessionFetched) {\n isLoading.current = true;\n }\n }, [isSessionFetched]);\n\n // Fetch session if it's not already fetched\n // We want this to happen only once, so the dependency array should not contain shouldFetchSession\n useEffect(() => {\n if (shouldFetchSession) {\n fetchSession();\n }\n }, [fetchSession]);\n return {\n isSessionLoading: isLoading.current,\n sessionToken: session,\n claims,\n isAuthenticated,\n };\n};\n\nexport default useSession;\n"],"names":["session","claims","isSessionLoading","isOidcLoading","fetchSession","isSessionFetched","isAuthenticated","useContext","isLoading","useRef","useMemo","current","shouldFetchSession","isDescopeBridge","useEffect","sessionToken"],"mappings":"iKAImB,KACjB,MAAMA,QACJA,EAAOC,OACPA,EAAMC,iBACNA,EAAgBC,cAChBA,EAAaC,aACbA,EAAYC,iBACZA,EAAgBC,gBAChBA,GACEC,EAAAA,UAIEC,EAAYC,EAAAA,OAAOP,GAAoBC,GAG7CO,EAAAA,SAAQ,KACNF,EAAUG,QAAUT,GAAoBC,CAAa,GACpD,CAACD,EAAkBC,IAGtB,MAAMS,GAAsBN,IAAoBJ,IAAqBW,EAAeA,kBAgBpF,OAbAH,EAAAA,SAAQ,KACFE,IAAuBP,IACzBG,EAAUG,SAAU,EACrB,GACA,CAACN,IAIJS,EAAAA,WAAU,KACJF,GACFR,GACD,GACA,CAACA,IACG,CACLF,iBAAkBM,EAAUG,QAC5BI,aAAcf,EACdC,SACAK,kBACD"}
1
+ {"version":3,"file":"useSession.js","sources":["../../../src/hooks/useSession.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport useContext from './useContext';\nimport { isDescopeBridge } from '../utils';\n\nconst useSession = () => {\n const {\n session,\n claims,\n isSessionLoading,\n isOidcLoading,\n fetchSession,\n isSessionFetchStarted,\n isSessionFetchCompleted,\n isAuthenticated,\n } = useContext();\n\n // when session should be received, we want the return value of \"isSessionLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isSessionLoading || isOidcLoading);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n // isSessionFetchCompleted guarantees a re-run when the fetch settles, even if isSessionLoading never visibly changed\n useMemo(() => {\n isLoading.current = isSessionLoading || isOidcLoading;\n }, [isSessionLoading, isOidcLoading, isSessionFetchCompleted]);\n\n // In case we're in a native flow, we won't refresh the session anyway, so no point in marking the state as loading\n const shouldFetchSession = !isAuthenticated && !isSessionLoading && !isDescopeBridge();\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchSession && !isSessionFetchStarted) {\n isLoading.current = true;\n }\n }, [isSessionFetchStarted]);\n\n // Fetch session if it's not already fetched\n // We want this to happen only once, so the dependency array should not contain shouldFetchSession\n useEffect(() => {\n if (shouldFetchSession) {\n fetchSession();\n }\n }, [fetchSession]);\n return {\n isSessionLoading: isLoading.current,\n sessionToken: session,\n claims,\n isAuthenticated,\n };\n};\n\nexport default useSession;\n"],"names":["session","claims","isSessionLoading","isOidcLoading","fetchSession","isSessionFetchStarted","isSessionFetchCompleted","isAuthenticated","useContext","default","isLoading","useRef","useMemo","current","shouldFetchSession","isDescopeBridge","useEffect","sessionToken"],"mappings":"iKAImB,KACjB,MAAMA,QACJA,EAAOC,OACPA,EAAMC,iBACNA,EAAgBC,cAChBA,EAAaC,aACbA,EAAYC,sBACZA,EAAqBC,wBACrBA,EAAuBC,gBACvBA,GACEC,EAAUC,UAIRC,EAAYC,EAAAA,OAAOT,GAAoBC,GAI7CS,EAAAA,SAAQ,KACNF,EAAUG,QAAUX,GAAoBC,CAAa,GACpD,CAACD,EAAkBC,EAAeG,IAGrC,MAAMQ,GAAsBP,IAAoBL,IAAqBa,EAAeA,kBAgBpF,OAbAH,EAAAA,SAAQ,KACFE,IAAuBT,IACzBK,EAAUG,SAAU,EACrB,GACA,CAACR,IAIJW,EAAAA,WAAU,KACJF,GACFV,GACD,GACA,CAACA,IACG,CACLF,iBAAkBQ,EAAUG,QAC5BI,aAAcjB,EACdC,SACAM,kBACD"}
@@ -1,2 +1,2 @@
1
- import e,{useState as t,useRef as r,useEffect as s,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:m=!1,refreshTokenViaCookie:l=!1,hooks:g,persistTokens:U=!0,autoRefresh:C=!0,oidcConfig:p,storeLastAuthenticatedUser:A=!0,keepLastAuthenticatedUserAfterLogout:L=!1,refreshCookieName:S="",getExternalToken:T,customStorage:b,children:j})=>{const[I,v]=t(),[x,N]=t(),[V,E]=t(),[F,R]=t(!1),[q,y]=t(!1),[O,P]=t(!1),[w,z]=t(!!p),B=r(!1),D=u({projectId:h,baseUrl:d,persistTokens:U,autoRefresh:C,sessionTokenViaCookie:m,refreshTokenViaCookie:l,hooks:g,oidcConfig:p,storeLastAuthenticatedUser:A,keepLastAuthenticatedUserAfterLogout:L,refreshCookieName:S,getExternalToken:T,customStorage:b});s((()=>{if(D){const e=D.onSessionTokenChange(N),t=D.onUserChange(v),r=D.onIsAuthenticatedChange(R),s=D.onClaimsChange(E);return()=>{e(),t(),r(),s()}}}),[D]);const G=r(!1),H=r(!1);s((()=>{D&&p&&!B.current&&(B.current=!0,D.oidc.finishLoginIfNeed().finally((()=>{z(!1),G.current=!0})))}),[]);const J=o((()=>{if(a())return;if(G.current)return;G.current=!0,P(!0);const e=()=>{requestAnimationFrame((()=>{setTimeout((()=>{P(!1)}),0)}))};c(null==D?void 0:D.refresh)(void 0,!0).then(e,e)}),[D]),K=o((()=>{if(H.current)return;H.current=!0,y(!0);const e=()=>y(!1);c(D.me)().then(e,e)}),[D]),M=n((()=>({fetchUser:K,user:I,isUserLoading:q,isUserFetched:H.current,fetchSession:J,session:x,isAuthenticated:F,isSessionLoading:O,isOidcLoading:w,isSessionFetched:G.current,projectId:h,baseUrl:d,baseStaticUrl:f,baseCdnUrl:k,storeLastAuthenticatedUser:A,keepLastAuthenticatedUserAfterLogout:L,refreshCookieName:S,customStorage:b,setUser:v,setSession:N,setIsAuthenticated:R,claims:V,sdk:D})),[K,I,q,H.current,J,x,F,O,w,G.current,h,d,f,k,L,S,b,v,N,R,V,D]);return e.createElement(i.Provider,{value:M},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: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};
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 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 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 // 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 (isSessionFetched.current) return;\n isSessionFetched.current = true;\n\n setIsSessionLoading(true);\n const stopSessionLoading = () => {\n // Defer to a separate render pass so React doesn't batch this with\n // the setIsSessionLoading(true) above when refresh() short-circuits\n // synchronously - downstream consumers (e.g. useSession) need to\n // observe the false→true→false loading transition (#1393)\n requestAnimationFrame(() => {\n setTimeout(() => {\n setIsSessionLoading(false);\n }, 0);\n });\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` - `isSessionFetched` 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 isSessionFetched: isSessionFetched.current,\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 isSessionFetched.current,\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","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","unsubscribeClaims","onClaimsChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","isDescopeBridge","stopSessionLoading","requestAnimationFrame","setTimeout","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,GAC/CsB,EAAsBC,GAAO,GAE7BC,EAAMC,EAAO,CACjBlC,YACAC,UACAM,gBACAC,cACAJ,wBACAC,wBACAC,QACAG,aACAC,6BACAC,uCACAC,oBACAC,mBACAC,kBAGFqB,GAAU,KACR,GAAIF,EAAK,CACP,MAAMG,EAA0BH,EAAII,qBAAqBjB,GACnDkB,EAAkBL,EAAIM,aAAatB,GACnCuB,EACJP,EAAIQ,wBAAwBjB,GACxBkB,EAAoBT,EAAIU,eAAerB,GAE7C,MAAO,KACLc,IACAE,IACAE,IACAE,GAAmB,CAEtB,CACe,GACf,CAACT,IAEJ,MAAMW,EAAmBZ,GAAO,GAC1Ba,EAAgBb,GAAO,GAI7BG,GAAU,KACJF,GAAOxB,IAAesB,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCnB,GAAiB,GAEjBc,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,GAAY,KAE/B,GAAIC,IAAmB,OAGvB,GAAIR,EAAiBE,QAAS,OAC9BF,EAAiBE,SAAU,EAE3BlB,GAAoB,GACpB,MAAMyB,EAAqB,KAKzBC,uBAAsB,KACpBC,YAAW,KACT3B,GAAoB,EAAM,GACzB,EAAE,GACL,EAOJ4B,EAAevB,eAAAA,EAAKwB,QAApBD,MAA6BE,GAAW,GAAMC,KAC5CN,EACAA,EACD,GACA,CAACpB,IAEE2B,EAAYT,GAAY,KAE5B,GAAIN,EAAcC,QAAS,OAC3BD,EAAcC,SAAU,EAExBpB,GAAiB,GAGjB,MAAMmC,EAAkB,IAAMnC,GAAiB,GAC/C8B,EAAevB,EAAI6B,GAAnBN,GAAyBG,KAAKE,EAAiBA,EAAgB,GAC9D,CAAC5B,IAEE8B,EAAQC,GACZ,KAAO,CACLJ,YACA5C,OACAS,gBACAoB,cAAeA,EAAcC,QAC7BI,eACA/B,UACAI,kBACAI,mBACAE,gBACAe,iBAAkBA,EAAiBE,QACnC9C,YACAC,UACAC,gBACAC,aACAO,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAY,SAEF,CACE2B,EACA5C,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB9C,EACAC,EACAC,EACAC,EACAQ,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAOgC,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 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,2 +1,2 @@
1
- const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"3.3.11"},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.13"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
2
2
  //# sourceMappingURL=constants.js.map
@@ -1,2 +1,2 @@
1
- import{useRef as s,useMemo as i,useEffect as t}from"react";import e from"./useContext.js";import{isDescopeBridge as o}from"../utils.js";const n=()=>{const{session:n,claims:r,isSessionLoading:c,isOidcLoading:a,fetchSession:u,isSessionFetched:d,isAuthenticated:m}=e(),f=s(c||a);i((()=>{f.current=c||a}),[c,a]);const h=!m&&!c&&!o();return i((()=>{h&&!d&&(f.current=!0)}),[d]),t((()=>{h&&u()}),[u]),{isSessionLoading:f.current,sessionToken:n,claims:r,isAuthenticated:m}};export{n as default};
1
+ import{useRef as s,useMemo as t,useEffect as e}from"react";import i from"./useContext.js";import{isDescopeBridge as o}from"../utils.js";const n=()=>{const{session:n,claims:r,isSessionLoading:c,isOidcLoading:a,fetchSession:d,isSessionFetchStarted:m,isSessionFetchCompleted:u,isAuthenticated:S}=i(),f=s(c||a);t((()=>{f.current=c||a}),[c,a,u]);const h=!S&&!c&&!o();return t((()=>{h&&!m&&(f.current=!0)}),[m]),e((()=>{h&&d()}),[d]),{isSessionLoading:f.current,sessionToken:n,claims:r,isAuthenticated:S}};export{n as default};
2
2
  //# sourceMappingURL=useSession.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSession.js","sources":["../../../src/hooks/useSession.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport useContext from './useContext';\nimport { isDescopeBridge } from '../utils';\n\nconst useSession = () => {\n const {\n session,\n claims,\n isSessionLoading,\n isOidcLoading,\n fetchSession,\n isSessionFetched,\n isAuthenticated,\n } = useContext();\n\n // when session should be received, we want the return value of \"isSessionLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isSessionLoading || isOidcLoading);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n isLoading.current = isSessionLoading || isOidcLoading;\n }, [isSessionLoading, isOidcLoading]);\n\n // In case we're in a native flow, we won't refresh the session anyway, so no point in marking the state as loading\n const shouldFetchSession = !isAuthenticated && !isSessionLoading && !isDescopeBridge();\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchSession && !isSessionFetched) {\n isLoading.current = true;\n }\n }, [isSessionFetched]);\n\n // Fetch session if it's not already fetched\n // We want this to happen only once, so the dependency array should not contain shouldFetchSession\n useEffect(() => {\n if (shouldFetchSession) {\n fetchSession();\n }\n }, [fetchSession]);\n return {\n isSessionLoading: isLoading.current,\n sessionToken: session,\n claims,\n isAuthenticated,\n };\n};\n\nexport default useSession;\n"],"names":["useSession","session","claims","isSessionLoading","isOidcLoading","fetchSession","isSessionFetched","isAuthenticated","useContext","isLoading","useRef","useMemo","current","shouldFetchSession","isDescopeBridge","useEffect","sessionToken"],"mappings":"wIAIM,MAAAA,EAAa,KACjB,MAAMC,QACJA,EAAOC,OACPA,EAAMC,iBACNA,EAAgBC,cAChBA,EAAaC,aACbA,EAAYC,iBACZA,EAAgBC,gBAChBA,GACEC,IAIEC,EAAYC,EAAOP,GAAoBC,GAG7CO,GAAQ,KACNF,EAAUG,QAAUT,GAAoBC,CAAa,GACpD,CAACD,EAAkBC,IAGtB,MAAMS,GAAsBN,IAAoBJ,IAAqBW,IAgBrE,OAbAH,GAAQ,KACFE,IAAuBP,IACzBG,EAAUG,SAAU,EACrB,GACA,CAACN,IAIJS,GAAU,KACJF,GACFR,GACD,GACA,CAACA,IACG,CACLF,iBAAkBM,EAAUG,QAC5BI,aAAcf,EACdC,SACAK,kBACD"}
1
+ {"version":3,"file":"useSession.js","sources":["../../../src/hooks/useSession.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport useContext from './useContext';\nimport { isDescopeBridge } from '../utils';\n\nconst useSession = () => {\n const {\n session,\n claims,\n isSessionLoading,\n isOidcLoading,\n fetchSession,\n isSessionFetchStarted,\n isSessionFetchCompleted,\n isAuthenticated,\n } = useContext();\n\n // when session should be received, we want the return value of \"isSessionLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isSessionLoading || isOidcLoading);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n // isSessionFetchCompleted guarantees a re-run when the fetch settles, even if isSessionLoading never visibly changed\n useMemo(() => {\n isLoading.current = isSessionLoading || isOidcLoading;\n }, [isSessionLoading, isOidcLoading, isSessionFetchCompleted]);\n\n // In case we're in a native flow, we won't refresh the session anyway, so no point in marking the state as loading\n const shouldFetchSession = !isAuthenticated && !isSessionLoading && !isDescopeBridge();\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchSession && !isSessionFetchStarted) {\n isLoading.current = true;\n }\n }, [isSessionFetchStarted]);\n\n // Fetch session if it's not already fetched\n // We want this to happen only once, so the dependency array should not contain shouldFetchSession\n useEffect(() => {\n if (shouldFetchSession) {\n fetchSession();\n }\n }, [fetchSession]);\n return {\n isSessionLoading: isLoading.current,\n sessionToken: session,\n claims,\n isAuthenticated,\n };\n};\n\nexport default useSession;\n"],"names":["useSession","session","claims","isSessionLoading","isOidcLoading","fetchSession","isSessionFetchStarted","isSessionFetchCompleted","isAuthenticated","useContext","isLoading","useRef","useMemo","current","shouldFetchSession","isDescopeBridge","useEffect","sessionToken"],"mappings":"wIAIM,MAAAA,EAAa,KACjB,MAAMC,QACJA,EAAOC,OACPA,EAAMC,iBACNA,EAAgBC,cAChBA,EAAaC,aACbA,EAAYC,sBACZA,EAAqBC,wBACrBA,EAAuBC,gBACvBA,GACEC,IAIEC,EAAYC,EAAOR,GAAoBC,GAI7CQ,GAAQ,KACNF,EAAUG,QAAUV,GAAoBC,CAAa,GACpD,CAACD,EAAkBC,EAAeG,IAGrC,MAAMO,GAAsBN,IAAoBL,IAAqBY,IAgBrE,OAbAH,GAAQ,KACFE,IAAuBR,IACzBI,EAAUG,SAAU,EACrB,GACA,CAACP,IAIJU,GAAU,KACJF,GACFT,GACD,GACA,CAACA,IACG,CACLF,iBAAkBO,EAAUG,QAC5BI,aAAchB,EACdC,SACAM,kBACD"}