@descope/react-sdk 2.30.9 → 2.30.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -204,7 +204,7 @@ const App = () => {
204
204
  A function that is called whenever there is a new screen state and after every next call. It receives the following parameters:
205
205
 
206
206
  - `screenName`: The name of the screen that is about to be rendered
207
- - `context`: An object containing the upcoming screen state
207
+ - `context`: An object containing the upcoming screen state. All server-produced screen data lives under `context.data`.
208
208
  - `next`: A function that, when called, continues the flow execution
209
209
  - `ref`: A reference to the descope-wc node
210
210
 
@@ -213,6 +213,13 @@ The function can be sync or async, and should return a boolean indicating whethe
213
213
  - `true`: Render a custom screen
214
214
  - `false`: Render the default flow screen
215
215
 
216
+ > **Breaking change (v-next):** server-produced screen data that used to sit directly on
217
+ > `context` now lives under **`context.data`** — e.g. `context.totp` → `context.data.totp`,
218
+ > `context.inboundAppApproveScopes` → `context.data.inboundAppApproveScopes`. Status,
219
+ > `form`, and identity fields (`user` / `project` / `lastAuth`) stay at the top level.
220
+ > See the [@descope/web-component README](https://www.npmjs.com/package/@descope/web-component#the-context-object)
221
+ > for the full list of `context.data` fields.
222
+
216
223
  This function allows rendering custom screens instead of the default flow screens.
217
224
  It can be useful for highly customized UIs or specific logic not covered by the default screens
218
225
 
@@ -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:L,children:m})=>{const[p,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),M=e.useRef(!1),w=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:L});e.useEffect((()=>{if(w){const e=w.onSessionTokenChange(T),t=w.onUserChange(A),s=w.onIsAuthenticatedChange(V),r=w.onClaimsChange(v);return()=>{e(),t(),s(),r()}}}),[w]);const y=e.useRef(!1),F=e.useRef(!1);e.useEffect((()=>{w&&k&&!M.current&&(M.current=!0,w.oidc.finishLoginIfNeed().finally((()=>{_(!1),y.current=!0})))}),[]);const O=e.useCallback((()=>{if(s.isDescopeBridge())return;if(y.current)return;y.current=!0,q(!0);const e=()=>{setTimeout((()=>{q(!1)}),0)};s.withValidation(null==w?void 0:w.refresh)(void 0,!0).then(e,e)}),[w]),P=e.useCallback((()=>{if(F.current)return;F.current=!0,E(!0);const e=()=>E(!1);s.withValidation(w.me)().then(e,e)}),[w]),B=e.useMemo((()=>({fetchUser:P,user:p,isUserLoading:x,isUserFetched:F.current,fetchSession:O,session:b,isAuthenticated:I,isSessionLoading:R,isOidcLoading:N,isSessionFetched:y.current,projectId:o,baseUrl:i,baseStaticUrl:a,baseCdnUrl:u,storeLastAuthenticatedUser:g,keepLastAuthenticatedUserAfterLogout:C,refreshCookieName:S,customStorage:L,setUser:A,setSession:T,setIsAuthenticated:V,claims:j,sdk:w})),[P,p,x,F.current,O,b,I,R,N,y.current,o,i,a,u,C,S,L,A,T,V,j,w]);return n.default.createElement(t.default.Provider,{value:B},m)};
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 const stopSessionLoading = () => {\n // Defer to a separate macrotask 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 // Deliberately not requestAnimationFrame: rAF callbacks don't run\n // while the tab is backgrounded (e.g. a login page opened from an\n // email magic link), which left isSessionLoading stuck true (#1433).\n // setTimeout always fires, visible tab or not.\n setTimeout(() => {\n setIsSessionLoading(false);\n }, 0);\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","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,KASzBC,YAAW,KACT1B,GAAoB,EAAM,GACzB,EAAE,EAOP2B,EAAcA,eAACtB,eAAAA,EAAKuB,QAApBD,MAA6BE,GAAW,GAAMC,KAC5CL,EACAA,EACD,GACA,CAACpB,IAEE0B,EAAYR,EAAAA,aAAY,KAE5B,GAAIN,EAAcC,QAAS,OAC3BD,EAAcC,SAAU,EAExBpB,GAAiB,GAGjB,MAAMkC,EAAkB,IAAMlC,GAAiB,GAC/C6B,EAAcA,eAACtB,EAAI4B,GAAnBN,GAAyBG,KAAKE,EAAiBA,EAAgB,GAC9D,CAAC3B,IAEE6B,EAAQC,EAAAA,SACZ,KAAO,CACLJ,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,OAAO+B,EAAAC,QAAAC,cAACC,UAAQC,SAAQ,CAACN,MAAOA,GAAQ/C,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,mBACA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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":"2.30.9"};
1
+ "use strict";const e="undefined"!=typeof window;exports.IS_BROWSER=e,exports.baseHeaders={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.30.11"};
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:l=!1,refreshTokenViaCookie:m=!1,hooks:g,persistTokens:U=!0,autoRefresh:C=!0,oidcConfig:p,storeLastAuthenticatedUser:L=!0,keepLastAuthenticatedUserAfterLogout:A=!1,refreshCookieName:S="",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=s(!1),D=u({projectId:h,baseUrl:d,persistTokens:U,autoRefresh:C,sessionTokenViaCookie:l,refreshTokenViaCookie:m,hooks:g,oidcConfig:p,storeLastAuthenticatedUser:L,keepLastAuthenticatedUserAfterLogout:A,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((()=>{if(a())return;if(G.current)return;G.current=!0,q(!0);const e=()=>{setTimeout((()=>{q(!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,O(!0);const e=()=>O(!1);c(D.me)().then(e,e)}),[D]),M=n((()=>({fetchUser:K,user:I,isUserLoading:y,isUserFetched:H.current,fetchSession:J,session:x,isAuthenticated:F,isSessionLoading:P,isOidcLoading:w,isSessionFetched:G.current,projectId:h,baseUrl:d,baseStaticUrl:f,baseCdnUrl:k,storeLastAuthenticatedUser:L,keepLastAuthenticatedUserAfterLogout:A,refreshCookieName:S,customStorage:b,setUser:v,setSession:N,setIsAuthenticated:R,claims:V,sdk:D})),[K,I,y,H.current,J,x,F,P,w,G.current,h,d,f,k,A,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 const stopSessionLoading = () => {\n // Defer to a separate macrotask 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 // Deliberately not requestAnimationFrame: rAF callbacks don't run\n // while the tab is backgrounded (e.g. a login page opened from an\n // email magic link), which left isSessionLoading stuck true (#1433).\n // setTimeout always fires, visible tab or not.\n setTimeout(() => {\n setIsSessionLoading(false);\n }, 0);\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","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,wB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S,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB9C,EACAC,EACAC,EACAC,EACAQ,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO+B,EAAAC,cAACC,EAAQC,SAAQ,CAACL,MAAOA,GAAQ/C,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":"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,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":"2.30.9"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
1
+ const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.30.11"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
2
2
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["declare const BUILD_VERSION: string;\n\nexport const baseHeaders = {\n 'x-descope-sdk-name': 'react',\n 'x-descope-sdk-version': BUILD_VERSION,\n};\n\n// This sdk can be used in SSR apps\nexport const IS_BROWSER = typeof window !== 'undefined';\n"],"names":["baseHeaders","IS_BROWSER","window"],"mappings":"AAEa,MAAAA,EAAc,CACzB,qBAAsB,QACtB,wBAAyB,UAIdC,EAA+B,oBAAXC"}
1
+ {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["declare const BUILD_VERSION: string;\n\nexport const baseHeaders = {\n 'x-descope-sdk-name': 'react',\n 'x-descope-sdk-version': BUILD_VERSION,\n};\n\n// This sdk can be used in SSR apps\nexport const IS_BROWSER = typeof window !== 'undefined';\n"],"names":["baseHeaders","IS_BROWSER","window"],"mappings":"AAEa,MAAAA,EAAc,CACzB,qBAAsB,QACtB,wBAAyB,WAIdC,EAA+B,oBAAXC"}