@descope/react-sdk 2.24.0 → 2.24.2

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 +1 @@
1
- {"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport { 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 autoRefresh?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n 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 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 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\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 setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n 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","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","fetchUser","me","value","useMemo","React","default","createElement","Context","Provider"],"mappings":"kQAoD6C,EAC3CA,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,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,CACjBjC,YACAC,UACAK,gBACAC,cACAH,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,KACjD5B,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEwB,EAAYN,EAAAA,aAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBpB,GAAiB,GACjB2B,EAAAA,eAAepB,EAAIyB,GAAnBL,GAAyBG,MAAK,KAC5B9B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEE0B,EAAQC,EAAAA,SACZ,KAAO,CACLH,YACAzC,OACAS,gBACAoB,cAAeA,EAAcC,QAC7BI,eACA/B,UACAI,kBACAI,mBACAE,gBACAe,iBAAkBA,EAAiBE,QACnC7C,YACAC,UACAC,gBACAC,aACAM,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAY,SAEF,CACEwB,EACAzC,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB7C,EACAC,EACAC,EACAC,EACAO,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO4B,EAAAC,QAAAC,cAACC,UAAQC,SAAQ,CAACN,MAAOA,GAAQ5C,EAA4B"}
1
+ {"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport { 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 autoRefresh?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n 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 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 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 setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n 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","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","fetchUser","me","value","useMemo","React","default","createElement","Context","Provider"],"mappings":"kQAoD6C,EAC3CA,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,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,CACjBjC,YACAC,UACAK,gBACAC,cACAH,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,KACjD5B,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEwB,EAAYN,EAAAA,aAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBpB,GAAiB,GACjB2B,EAAAA,eAAepB,EAAIyB,GAAnBL,GAAyBG,MAAK,KAC5B9B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEE0B,EAAQC,EAAAA,SACZ,KAAO,CACLH,YACAzC,OACAS,gBACAoB,cAAeA,EAAcC,QAC7BI,eACA/B,UACAI,kBACAI,mBACAE,gBACAe,iBAAkBA,EAAiBE,QACnC7C,YACAC,UACAC,gBACAC,aACAM,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAY,SAEF,CACEwB,EACAzC,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB7C,EACAC,EACAC,EACAC,EACAO,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO4B,EAAAC,QAAAC,cAACC,UAAQC,SAAQ,CAACN,MAAOA,GAAQ5C,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.24.0"};
1
+ "use strict";const e="undefined"!=typeof window;exports.IS_BROWSER=e,exports.baseHeaders={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.24.2"};
2
2
  //# sourceMappingURL=constants.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),s=require("./useContext.js");exports.default=()=>{const{session:t,claims:i,isSessionLoading:n,isOidcLoading:o,fetchSession:r,isSessionFetched:u,isAuthenticated:c}=s.default(),a=e.useRef(n||o);e.useMemo((()=>{a.current=n||o}),[n,o]);const d=!c&&!n;return e.useMemo((()=>{d&&!u&&(a.current=!0)}),[u]),e.useEffect((()=>{d&&r()}),[r]),{isSessionLoading:a.current,sessionToken:t,claims:i,isAuthenticated:c}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),s=require("./useContext.js"),i=require("../utils.js");exports.default=()=>{const{session:t,claims:r,isSessionLoading:n,isOidcLoading:o,fetchSession:u,isSessionFetched:c,isAuthenticated:a}=s.default(),d=e.useRef(n||o);e.useMemo((()=>{d.current=n||o}),[n,o]);const f=!a&&!n&&!i.isDescopeBridge();return e.useMemo((()=>{f&&!c&&(d.current=!0)}),[c]),e.useEffect((()=>{f&&u()}),[u]),{isSessionLoading:d.current,sessionToken:t,claims:r,isAuthenticated:a}};
2
2
  //# sourceMappingURL=useSession.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSession.js","sources":["../../../src/hooks/useSession.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport useContext from './useContext';\n\nconst useSession = () => {\n const {\n session,\n claims,\n isSessionLoading,\n isOidcLoading,\n fetchSession,\n isSessionFetched,\n isAuthenticated,\n } = useContext();\n\n // when session should be received, we want the return value of \"isSessionLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isSessionLoading || isOidcLoading);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n isLoading.current = isSessionLoading || isOidcLoading;\n }, [isSessionLoading, isOidcLoading]);\n\n const shouldFetchSession = !isAuthenticated && !isSessionLoading;\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchSession && !isSessionFetched) {\n isLoading.current = true;\n }\n }, [isSessionFetched]);\n\n // Fetch session if it's not already fetched\n // We want this to happen only once, so the dependency array should not contain shouldFetchSession\n useEffect(() => {\n if (shouldFetchSession) {\n fetchSession();\n }\n }, [fetchSession]);\n return {\n isSessionLoading: isLoading.current,\n sessionToken: session,\n claims,\n isAuthenticated,\n };\n};\n\nexport default useSession;\n"],"names":["session","claims","isSessionLoading","isOidcLoading","fetchSession","isSessionFetched","isAuthenticated","useContext","isLoading","useRef","useMemo","current","shouldFetchSession","useEffect","sessionToken"],"mappings":"wIAGmB,KACjB,MAAMA,QACJA,EAAOC,OACPA,EAAMC,iBACNA,EAAgBC,cAChBA,EAAaC,aACbA,EAAYC,iBACZA,EAAgBC,gBAChBA,GACEC,EAAAA,UAIEC,EAAYC,EAAAA,OAAOP,GAAoBC,GAG7CO,EAAAA,SAAQ,KACNF,EAAUG,QAAUT,GAAoBC,CAAa,GACpD,CAACD,EAAkBC,IAEtB,MAAMS,GAAsBN,IAAoBJ,EAgBhD,OAbAQ,EAAAA,SAAQ,KACFE,IAAuBP,IACzBG,EAAUG,SAAU,EACrB,GACA,CAACN,IAIJQ,EAAAA,WAAU,KACJD,GACFR,GACD,GACA,CAACA,IACG,CACLF,iBAAkBM,EAAUG,QAC5BG,aAAcd,EACdC,SACAK,kBACD"}
1
+ {"version":3,"file":"useSession.js","sources":["../../../src/hooks/useSession.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport useContext from './useContext';\nimport { isDescopeBridge } from '../utils';\n\nconst useSession = () => {\n const {\n session,\n claims,\n isSessionLoading,\n isOidcLoading,\n fetchSession,\n isSessionFetched,\n isAuthenticated,\n } = useContext();\n\n // when session should be received, we want the return value of \"isSessionLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isSessionLoading || isOidcLoading);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n isLoading.current = isSessionLoading || isOidcLoading;\n }, [isSessionLoading, isOidcLoading]);\n\n // In case we're in a native flow, we won't refresh the session anyway, so no point in marking the state as loading\n const shouldFetchSession = !isAuthenticated && !isSessionLoading && !isDescopeBridge();\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchSession && !isSessionFetched) {\n isLoading.current = true;\n }\n }, [isSessionFetched]);\n\n // Fetch session if it's not already fetched\n // We want this to happen only once, so the dependency array should not contain shouldFetchSession\n useEffect(() => {\n if (shouldFetchSession) {\n fetchSession();\n }\n }, [fetchSession]);\n return {\n isSessionLoading: isLoading.current,\n sessionToken: session,\n claims,\n isAuthenticated,\n };\n};\n\nexport default useSession;\n"],"names":["session","claims","isSessionLoading","isOidcLoading","fetchSession","isSessionFetched","isAuthenticated","useContext","isLoading","useRef","useMemo","current","shouldFetchSession","isDescopeBridge","useEffect","sessionToken"],"mappings":"iKAImB,KACjB,MAAMA,QACJA,EAAOC,OACPA,EAAMC,iBACNA,EAAgBC,cAChBA,EAAaC,aACbA,EAAYC,iBACZA,EAAgBC,gBAChBA,GACEC,EAAAA,UAIEC,EAAYC,EAAAA,OAAOP,GAAoBC,GAG7CO,EAAAA,SAAQ,KACNF,EAAUG,QAAUT,GAAoBC,CAAa,GACpD,CAACD,EAAkBC,IAGtB,MAAMS,GAAsBN,IAAoBJ,IAAqBW,EAAeA,kBAgBpF,OAbAH,EAAAA,SAAQ,KACFE,IAAuBP,IACzBG,EAAUG,SAAU,EACrB,GACA,CAACN,IAIJS,EAAAA,WAAU,KACJF,GACFR,GACD,GACA,CAACA,IACG,CACLF,iBAAkBM,EAAUG,QAC5BI,aAAcf,EACdC,SACAK,kBACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport { 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 autoRefresh?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n 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 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 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\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 setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n 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","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","fetchUser","me","value","useMemo","React","createElement","Context","Provider"],"mappings":"mOAoDA,MAAMA,EAAuC,EAC3CC,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,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,CACjBjC,YACAC,UACAK,gBACAC,cACAH,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,KACjD5B,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEwB,EAAYN,GAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBpB,GAAiB,GACjB2B,EAAepB,EAAIyB,GAAnBL,GAAyBG,MAAK,KAC5B9B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEE0B,EAAQC,GACZ,KAAO,CACLH,YACAzC,OACAS,gBACAoB,cAAeA,EAAcC,QAC7BI,eACA/B,UACAI,kBACAI,mBACAE,gBACAe,iBAAkBA,EAAiBE,QACnC7C,YACAC,UACAC,gBACAC,aACAM,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAY,SAEF,CACEwB,EACAzC,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB7C,EACAC,EACAC,EACAC,EACAO,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO4B,EAAAC,cAACC,EAAQC,SAAQ,CAACL,MAAOA,GAAQ5C,EAA4B"}
1
+ {"version":3,"file":"AuthProvider.js","sources":["../../../../src/components/AuthProvider/AuthProvider.tsx"],"sourcesContent":["import React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport { 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 autoRefresh?: boolean;\n // If true, session token (jwt) will be stored on cookie. Otherwise, the session token will be\n // stored on local storage and can accessed with getSessionToken function\n // Use this option if session token will stay small (less than 1k)\n // NOTE: Session token can grow, especially in cases of using authorization, or adding custom claims\n sessionTokenViaCookie?: CookieConfig;\n 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 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 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 setIsSessionLoading(false);\n });\n }, [sdk]);\n\n const fetchUser = useCallback(() => {\n // We want that the user will fetched only once\n if (isUserFetched.current) return;\n isUserFetched.current = true;\n\n setIsUserLoading(true);\n withValidation(sdk.me)().then(() => {\n setIsUserLoading(false);\n });\n }, [sdk]);\n\n const value = useMemo<IContext>(\n () => ({\n fetchUser,\n user,\n isUserLoading,\n isUserFetched: isUserFetched.current,\n fetchSession,\n session,\n isAuthenticated,\n isSessionLoading,\n isOidcLoading,\n isSessionFetched: isSessionFetched.current,\n projectId,\n baseUrl,\n baseStaticUrl,\n 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","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","fetchUser","me","value","useMemo","React","createElement","Context","Provider"],"mappings":"mOAoDA,MAAMA,EAAuC,EAC3CC,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,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,CACjBjC,YACAC,UACAK,gBACAC,cACAH,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,KACjD5B,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEwB,EAAYN,GAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBpB,GAAiB,GACjB2B,EAAepB,EAAIyB,GAAnBL,GAAyBG,MAAK,KAC5B9B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEE0B,EAAQC,GACZ,KAAO,CACLH,YACAzC,OACAS,gBACAoB,cAAeA,EAAcC,QAC7BI,eACA/B,UACAI,kBACAI,mBACAE,gBACAe,iBAAkBA,EAAiBE,QACnC7C,YACAC,UACAC,gBACAC,aACAM,6BACAC,uCACAC,oBACAE,gBACAG,UACAG,aACAI,qBACAH,SACAY,SAEF,CACEwB,EACAzC,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB7C,EACAC,EACAC,EACAC,EACAO,EACAC,EACAE,EACAG,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO4B,EAAAC,cAACC,EAAQC,SAAQ,CAACL,MAAOA,GAAQ5C,EAA4B"}
@@ -1,2 +1,2 @@
1
- const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.24.0"},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.24.2"},d="undefined"!=typeof window;export{d as IS_BROWSER,e as baseHeaders};
2
2
  //# sourceMappingURL=constants.js.map
@@ -1,2 +1,2 @@
1
- import{useRef as s,useMemo as e,useEffect as i}from"react";import t from"./useContext.js";const n=()=>{const{session:n,claims:o,isSessionLoading:c,isOidcLoading:r,fetchSession:a,isSessionFetched:d,isAuthenticated:u}=t(),m=s(c||r);e((()=>{m.current=c||r}),[c,r]);const f=!u&&!c;return e((()=>{f&&!d&&(m.current=!0)}),[d]),i((()=>{f&&a()}),[a]),{isSessionLoading:m.current,sessionToken:n,claims:o,isAuthenticated:u}};export{n as default};
1
+ import{useRef as s,useMemo as i,useEffect as t}from"react";import e from"./useContext.js";import{isDescopeBridge as o}from"../utils.js";const n=()=>{const{session:n,claims:r,isSessionLoading:c,isOidcLoading:a,fetchSession:u,isSessionFetched:d,isAuthenticated:m}=e(),f=s(c||a);i((()=>{f.current=c||a}),[c,a]);const h=!m&&!c&&!o();return i((()=>{h&&!d&&(f.current=!0)}),[d]),t((()=>{h&&u()}),[u]),{isSessionLoading:f.current,sessionToken:n,claims:r,isAuthenticated:m}};export{n as default};
2
2
  //# sourceMappingURL=useSession.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSession.js","sources":["../../../src/hooks/useSession.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport useContext from './useContext';\n\nconst useSession = () => {\n const {\n session,\n claims,\n isSessionLoading,\n isOidcLoading,\n fetchSession,\n isSessionFetched,\n isAuthenticated,\n } = useContext();\n\n // when session should be received, we want the return value of \"isSessionLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isSessionLoading || isOidcLoading);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n isLoading.current = isSessionLoading || isOidcLoading;\n }, [isSessionLoading, isOidcLoading]);\n\n const shouldFetchSession = !isAuthenticated && !isSessionLoading;\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchSession && !isSessionFetched) {\n isLoading.current = true;\n }\n }, [isSessionFetched]);\n\n // Fetch session if it's not already fetched\n // We want this to happen only once, so the dependency array should not contain shouldFetchSession\n useEffect(() => {\n if (shouldFetchSession) {\n fetchSession();\n }\n }, [fetchSession]);\n return {\n isSessionLoading: isLoading.current,\n sessionToken: session,\n claims,\n isAuthenticated,\n };\n};\n\nexport default useSession;\n"],"names":["useSession","session","claims","isSessionLoading","isOidcLoading","fetchSession","isSessionFetched","isAuthenticated","useContext","isLoading","useRef","useMemo","current","shouldFetchSession","useEffect","sessionToken"],"mappings":"0FAGM,MAAAA,EAAa,KACjB,MAAMC,QACJA,EAAOC,OACPA,EAAMC,iBACNA,EAAgBC,cAChBA,EAAaC,aACbA,EAAYC,iBACZA,EAAgBC,gBAChBA,GACEC,IAIEC,EAAYC,EAAOP,GAAoBC,GAG7CO,GAAQ,KACNF,EAAUG,QAAUT,GAAoBC,CAAa,GACpD,CAACD,EAAkBC,IAEtB,MAAMS,GAAsBN,IAAoBJ,EAgBhD,OAbAQ,GAAQ,KACFE,IAAuBP,IACzBG,EAAUG,SAAU,EACrB,GACA,CAACN,IAIJQ,GAAU,KACJD,GACFR,GACD,GACA,CAACA,IACG,CACLF,iBAAkBM,EAAUG,QAC5BG,aAAcd,EACdC,SACAK,kBACD"}
1
+ {"version":3,"file":"useSession.js","sources":["../../../src/hooks/useSession.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport useContext from './useContext';\nimport { isDescopeBridge } from '../utils';\n\nconst useSession = () => {\n const {\n session,\n claims,\n isSessionLoading,\n isOidcLoading,\n fetchSession,\n isSessionFetched,\n isAuthenticated,\n } = useContext();\n\n // when session should be received, we want the return value of \"isSessionLoading\" to be true starting from the first call\n // (and not only when receiving an update from the context)\n const isLoading = useRef(isSessionLoading || isOidcLoading);\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n isLoading.current = isSessionLoading || isOidcLoading;\n }, [isSessionLoading, isOidcLoading]);\n\n // In case we're in a native flow, we won't refresh the session anyway, so no point in marking the state as loading\n const shouldFetchSession = !isAuthenticated && !isSessionLoading && !isDescopeBridge();\n\n // we want this to happen before returning a value so we are using \"useMemo\" and not \"useEffect\"\n useMemo(() => {\n if (shouldFetchSession && !isSessionFetched) {\n isLoading.current = true;\n }\n }, [isSessionFetched]);\n\n // Fetch session if it's not already fetched\n // We want this to happen only once, so the dependency array should not contain shouldFetchSession\n useEffect(() => {\n if (shouldFetchSession) {\n fetchSession();\n }\n }, [fetchSession]);\n return {\n isSessionLoading: isLoading.current,\n sessionToken: session,\n claims,\n isAuthenticated,\n };\n};\n\nexport default useSession;\n"],"names":["useSession","session","claims","isSessionLoading","isOidcLoading","fetchSession","isSessionFetched","isAuthenticated","useContext","isLoading","useRef","useMemo","current","shouldFetchSession","isDescopeBridge","useEffect","sessionToken"],"mappings":"wIAIM,MAAAA,EAAa,KACjB,MAAMC,QACJA,EAAOC,OACPA,EAAMC,iBACNA,EAAgBC,cAChBA,EAAaC,aACbA,EAAYC,iBACZA,EAAgBC,gBAChBA,GACEC,IAIEC,EAAYC,EAAOP,GAAoBC,GAG7CO,GAAQ,KACNF,EAAUG,QAAUT,GAAoBC,CAAa,GACpD,CAACD,EAAkBC,IAGtB,MAAMS,GAAsBN,IAAoBJ,IAAqBW,IAgBrE,OAbAH,GAAQ,KACFE,IAAuBP,IACzBG,EAAUG,SAAU,EACrB,GACA,CAACN,IAIJS,GAAU,KACJF,GACFR,GACD,GACA,CAACA,IACG,CACLF,iBAAkBM,EAAUG,QAC5BI,aAAcf,EACdC,SACAK,kBACD"}
package/dist/index.d.ts CHANGED
@@ -594,7 +594,7 @@ declare const createSdkWrapper: <P extends {
594
594
  }, token?: string) => Promise<_1.SdkResponse<_1.URLResponse>>;
595
595
  };
596
596
  saml: {
597
- start: (tenantIdOrEmail: string, redirectUrl?: string, loginOptions?: _1.LoginOptions, token?: string, ssoId?: string, forceAuthn?: boolean, loginHint?: string) => Promise<_1.SdkResponse<_1.URLResponse>>;
597
+ start: (tenantIdOrEmail: string, redirectUrl?: string, loginOptions?: _1.LoginOptions, token?: string, ssoId?: string, forceAuthn?: boolean, loginHint?: string, enforceInitiatedEmail?: boolean) => Promise<_1.SdkResponse<_1.URLResponse>>;
598
598
  exchange: (code: string) => Promise<_1.SdkResponse<_1.JWTResponse>>;
599
599
  };
600
600
  totp: {
@@ -1240,7 +1240,7 @@ declare const createSdkWrapper: <P extends {
1240
1240
  }, token?: string) => Promise<_1.SdkResponse<_1.URLResponse>>;
1241
1241
  };
1242
1242
  saml: {
1243
- start: (tenantIdOrEmail: string, redirectUrl?: string, loginOptions?: _1.LoginOptions, token?: string, ssoId?: string, forceAuthn?: boolean, loginHint?: string) => Promise<_1.SdkResponse<_1.URLResponse>>;
1243
+ start: (tenantIdOrEmail: string, redirectUrl?: string, loginOptions?: _1.LoginOptions, token?: string, ssoId?: string, forceAuthn?: boolean, loginHint?: string, enforceInitiatedEmail?: boolean) => Promise<_1.SdkResponse<_1.URLResponse>>;
1244
1244
  exchange: (code: string) => Promise<_1.SdkResponse<_1.JWTResponse>>;
1245
1245
  };
1246
1246
  totp: {
@@ -1886,7 +1886,7 @@ declare const createSdkWrapper: <P extends {
1886
1886
  }, token?: string) => Promise<_1.SdkResponse<_1.URLResponse>>;
1887
1887
  };
1888
1888
  saml: {
1889
- start: (tenantIdOrEmail: string, redirectUrl?: string, loginOptions?: _1.LoginOptions, token?: string, ssoId?: string, forceAuthn?: boolean, loginHint?: string) => Promise<_1.SdkResponse<_1.URLResponse>>;
1889
+ start: (tenantIdOrEmail: string, redirectUrl?: string, loginOptions?: _1.LoginOptions, token?: string, ssoId?: string, forceAuthn?: boolean, loginHint?: string, enforceInitiatedEmail?: boolean) => Promise<_1.SdkResponse<_1.URLResponse>>;
1890
1890
  exchange: (code: string) => Promise<_1.SdkResponse<_1.JWTResponse>>;
1891
1891
  };
1892
1892
  totp: {