@descope/react-sdk 0.0.0-next-94de8ba2-20260626 → 0.0.0-next-f8bdf285-20260715

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 i=o(e);exports.default=({projectId:o,baseUrl:n="",baseStaticUrl:a="",baseCdnUrl:u="",sessionTokenViaCookie:c=!1,refreshTokenViaCookie:d=!1,hooks:h,persistTokens:f=!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:n,persistTokens:f,autoRefresh:l,sessionTokenViaCookie:c,refreshTokenViaCookie:d,hooks:h,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((()=>{s.isDescopeBridge()||w.current||(w.current=!0,R(!0),s.withValidation(null==M?void 0:M.refresh)(void 0,!0).then((()=>{requestAnimationFrame((()=>{setTimeout((()=>{R(!1)}),0)}))})))}),[M]),P=e.useCallback((()=>{y.current||(y.current=!0,x(!0),s.withValidation(M.me)().then((()=>{x(!1)})))}),[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:n,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,n,a,u,C,S,m,p,T,V,j,M]);return i.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: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)};
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 withValidation(sdk?.refresh)(undefined, true).then(() => {\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 }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n 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","withValidation","refresh","undefined","then","requestAnimationFrame","setTimeout","fetchUser","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,KAE3BC,qBAGAR,EAAiBE,UACrBF,EAAiBE,SAAU,EAE3BlB,GAAoB,GACpByB,EAAAA,eAAepB,aAAA,EAAAA,EAAKqB,QAApBD,MAA6BE,GAAW,GAAMC,MAAK,KAKjDC,uBAAsB,KACpBC,YAAW,KACT9B,GAAoB,EAAM,GACzB,EAAE,GACL,IACF,GACD,CAACK,IAEE0B,EAAYR,EAAAA,aAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBpB,GAAiB,GACjB2B,EAAAA,eAAepB,EAAI2B,GAAnBP,GAAyBG,MAAK,KAC5B9B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEE4B,EAAQC,EAAAA,SACZ,KAAO,CACLH,YACA3C,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,CACE0B,EACA3C,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB9C,EACAC,EACAC,EACAC,EACAQ,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO8B,EAAAC,QAAAC,cAACC,UAAQC,SAAQ,CAACN,MAAOA,GAAQ9C,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 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,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":"0.0.0-next-94de8ba2-20260626"};
1
+ "use strict";const e="undefined"!=typeof window;exports.IS_BROWSER=e,exports.baseHeaders={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.0-next-f8bdf285-20260715"};
2
2
  //# sourceMappingURL=constants.js.map
@@ -1,2 +1,2 @@
1
- import e,{useState as t,useRef as s,useEffect as r,useCallback as o,useMemo as n}from"react";import i from"../../hooks/Context.js";import{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=s(!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});r((()=>{if(D){const e=D.onSessionTokenChange(N),t=D.onUserChange(v),s=D.onIsAuthenticatedChange(R),r=D.onClaimsChange(E);return()=>{e(),t(),s(),r()}}}),[D]);const G=s(!1),H=s(!1);r((()=>{D&&p&&!B.current&&(B.current=!0,D.oidc.finishLoginIfNeed().finally((()=>{z(!1),G.current=!0})))}),[]);const J=o((()=>{a()||G.current||(G.current=!0,P(!0),c(null==D?void 0:D.refresh)(void 0,!0).then((()=>{requestAnimationFrame((()=>{setTimeout((()=>{P(!1)}),0)}))})))}),[D]),K=o((()=>{H.current||(H.current=!0,y(!0),c(D.me)().then((()=>{y(!1)})))}),[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 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};
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 withValidation(sdk?.refresh)(undefined, true).then(() => {\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 }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n 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","withValidation","refresh","undefined","then","requestAnimationFrame","setTimeout","fetchUser","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,KAE3BC,KAGAR,EAAiBE,UACrBF,EAAiBE,SAAU,EAE3BlB,GAAoB,GACpByB,EAAepB,aAAA,EAAAA,EAAKqB,QAApBD,MAA6BE,GAAW,GAAMC,MAAK,KAKjDC,uBAAsB,KACpBC,YAAW,KACT9B,GAAoB,EAAM,GACzB,EAAE,GACL,IACF,GACD,CAACK,IAEE0B,EAAYR,GAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBpB,GAAiB,GACjB2B,EAAepB,EAAI2B,GAAnBP,GAAyBG,MAAK,KAC5B9B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEE4B,EAAQC,GACZ,KAAO,CACLH,YACA3C,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,CACE0B,EACA3C,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB9C,EACAC,EACAC,EACAC,EACAQ,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO8B,EAAAC,cAACC,EAAQC,SAAQ,CAACL,MAAOA,GAAQ9C,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 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,2 +1,2 @@
1
- const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.0-next-94de8ba2-20260626"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
1
+ const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"0.0.0-next-f8bdf285-20260715"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
2
2
  //# sourceMappingURL=constants.js.map
package/dist/index.d.ts CHANGED
@@ -150,13 +150,17 @@ declare const createSdkWrapper: <P extends {
150
150
  create: boolean;
151
151
  }>>;
152
152
  };
153
- update: ((identifier: string, token?: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<_1.ResponseData>>) & {
154
- start: (loginId: string, origin: string, token?: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<{
153
+ update: ((identifier: string, token?: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<_1.ResponseData> | _1.SdkResponse<{
154
+ jwt?: _1.JWTResponse;
155
+ }>>) & {
156
+ start: (loginId: string, origin: string, token?: string, passkeyOptions?: _1.PasskeyOptions, mfa?: boolean) => Promise<_1.SdkResponse<{
155
157
  transactionId: string;
156
158
  options: string;
157
159
  create: boolean;
158
160
  }>>;
159
- finish: (transactionId: string, response: string) => Promise<_1.SdkResponse<_1.ResponseData>>;
161
+ finish: (transactionId: string, response: string) => Promise<_1.SdkResponse<{
162
+ jwt?: _1.JWTResponse;
163
+ }>>;
160
164
  };
161
165
  helpers: {
162
166
  create: (options: string) => Promise<string>;
@@ -908,13 +912,17 @@ declare const createSdkWrapper: <P extends {
908
912
  create: boolean;
909
913
  }>>;
910
914
  };
911
- update: ((identifier: string, token?: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<_1.ResponseData>>) & {
912
- start: (loginId: string, origin: string, token?: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<{
915
+ update: ((identifier: string, token?: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<_1.ResponseData> | _1.SdkResponse<{
916
+ jwt?: _1.JWTResponse;
917
+ }>>) & {
918
+ start: (loginId: string, origin: string, token?: string, passkeyOptions?: _1.PasskeyOptions, mfa?: boolean) => Promise<_1.SdkResponse<{
913
919
  transactionId: string;
914
920
  options: string;
915
921
  create: boolean;
916
922
  }>>;
917
- finish: (transactionId: string, response: string) => Promise<_1.SdkResponse<_1.ResponseData>>;
923
+ finish: (transactionId: string, response: string) => Promise<_1.SdkResponse<{
924
+ jwt?: _1.JWTResponse;
925
+ }>>;
918
926
  };
919
927
  helpers: {
920
928
  create: (options: string) => Promise<string>;
@@ -1666,13 +1674,17 @@ declare const createSdkWrapper: <P extends {
1666
1674
  create: boolean;
1667
1675
  }>>;
1668
1676
  };
1669
- update: ((identifier: string, token?: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<_1.ResponseData>>) & {
1670
- start: (loginId: string, origin: string, token?: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<{
1677
+ update: ((identifier: string, token?: string, passkeyOptions?: _1.PasskeyOptions) => Promise<_1.SdkResponse<_1.ResponseData> | _1.SdkResponse<{
1678
+ jwt?: _1.JWTResponse;
1679
+ }>>) & {
1680
+ start: (loginId: string, origin: string, token?: string, passkeyOptions?: _1.PasskeyOptions, mfa?: boolean) => Promise<_1.SdkResponse<{
1671
1681
  transactionId: string;
1672
1682
  options: string;
1673
1683
  create: boolean;
1674
1684
  }>>;
1675
- finish: (transactionId: string, response: string) => Promise<_1.SdkResponse<_1.ResponseData>>;
1685
+ finish: (transactionId: string, response: string) => Promise<_1.SdkResponse<{
1686
+ jwt?: _1.JWTResponse;
1687
+ }>>;
1676
1688
  };
1677
1689
  helpers: {
1678
1690
  create: (options: string) => Promise<string>;