@descope/react-sdk 2.19.3 → 2.20.1
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 +5 -2
- package/dist/cjs/components/AuthProvider/AuthProvider.js +1 -1
- package/dist/cjs/components/AuthProvider/AuthProvider.js.map +1 -1
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/hooks/useSession.js +1 -1
- package/dist/cjs/hooks/useSession.js.map +1 -1
- package/dist/esm/components/AuthProvider/AuthProvider.js +1 -1
- package/dist/esm/components/AuthProvider/AuthProvider.js.map +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/hooks/useSession.js +1 -1
- package/dist/esm/hooks/useSession.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/types/hooks/useSession.d.ts +1 -0
- package/dist/types/sdk.d.ts +3 -0
- package/dist/types/types.d.ts +1 -0
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -254,9 +254,9 @@ import { useCallback } from 'react';
|
|
|
254
254
|
const App = () => {
|
|
255
255
|
// NOTE - `useDescope`, `useSession`, `useUser` should be used inside `AuthProvider` context,
|
|
256
256
|
// and will throw an exception if this requirement is not met
|
|
257
|
-
// useSession retrieves authentication state, session loading status, and session token
|
|
257
|
+
// useSession retrieves authentication state, session loading status, useful claims, and the session token
|
|
258
258
|
// If the session token is managed in cookies in project settings, sessionToken will be empty.
|
|
259
|
-
const { isAuthenticated, isSessionLoading, sessionToken } = useSession();
|
|
259
|
+
const { isAuthenticated, isSessionLoading, sessionToken, claims } = useSession();
|
|
260
260
|
// useUser retrieves the logged in user information
|
|
261
261
|
const { user, isUserLoading } = useUser();
|
|
262
262
|
// useDescope retrieves Descope SDK for further operations related to authentication
|
|
@@ -389,6 +389,9 @@ If you need to customize this, you can set `sessionTokenViaCookie={sameSite: 'La
|
|
|
389
389
|
|
|
390
390
|
If project settings are configured to manage session token in cookies, Descope services will automatically set the session token in the `DS` cookie as a `Secure` and `HttpOnly` cookie. In this case, the session token will not be stored in the browser's and will not be accessible to the client-side code using `useSession` or `getSessionToken`.
|
|
391
391
|
|
|
392
|
+
However, `useSession`'s returned `claims` field will always be available to retrieve custom claims & common Descope claims
|
|
393
|
+
from the token.
|
|
394
|
+
|
|
392
395
|
````js
|
|
393
396
|
### Helper Functions
|
|
394
397
|
|
|
@@ -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 n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);exports.default=({projectId:n,baseUrl:
|
|
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 n(e){return e&&e.__esModule?e:{default:e}}var o=n(e);exports.default=({projectId:n,baseUrl:a="",baseStaticUrl:i="",baseCdnUrl:u="",sessionTokenViaCookie:c=!1,persistTokens:d=!0,autoRefresh:l=!0,oidcConfig:f,storeLastAuthenticatedUser:h=!0,keepLastAuthenticatedUserAfterLogout:k=!1,refreshCookieName:U="",getExternalToken:C,children:g})=>{const[S,L]=e.useState(),[A,p]=e.useState(),[b,m]=e.useState(),[j,v]=e.useState(!1),[T,I]=e.useState(!1),[x,E]=e.useState(!1),[R,q]=e.useState(!!f),N=e.useRef(!1),V=r.default({projectId:n,baseUrl:a,persistTokens:d,autoRefresh:l,sessionTokenViaCookie:c,oidcConfig:f,storeLastAuthenticatedUser:h,keepLastAuthenticatedUserAfterLogout:k,refreshCookieName:U,getExternalToken:C});e.useEffect((()=>{if(V){const e=V.onSessionTokenChange(p),t=V.onUserChange(L),s=V.onIsAuthenticatedChange(v),r=V.onClaimsChange(m);return()=>{e(),t(),s(),r()}}}),[V]);const _=e.useRef(!1),M=e.useRef(!1);e.useEffect((()=>{V&&f&&!N.current&&(N.current=!0,V.oidc.finishLoginIfNeed().finally((()=>{q(!1),_.current=!0})))}),[]);const w=e.useCallback((()=>{_.current||(_.current=!0,E(!0),s.withValidation(null==V?void 0:V.refresh)(void 0,!0).then((()=>{E(!1)})))}),[V]),y=e.useCallback((()=>{M.current||(M.current=!0,I(!0),s.withValidation(V.me)().then((()=>{I(!1)})))}),[V]),F=e.useMemo((()=>({fetchUser:y,user:S,isUserLoading:T,isUserFetched:M.current,fetchSession:w,session:A,isAuthenticated:j,isSessionLoading:x,isOidcLoading:R,isSessionFetched:_.current,projectId:n,baseUrl:a,baseStaticUrl:i,baseCdnUrl:u,storeLastAuthenticatedUser:h,keepLastAuthenticatedUserAfterLogout:k,refreshCookieName:U,setUser:L,setSession:p,setIsAuthenticated:v,claims:b,sdk:V})),[y,S,T,M.current,w,A,j,x,R,_.current,n,a,i,u,k,U,L,p,v,b,V]);return o.default.createElement(t.default.Provider,{value:F},g)};
|
|
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 { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { withValidation } from '../../utils';\nimport useSdk from './useSdk';\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 // 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 children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\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 oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\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\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\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 // 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 setUser,\n setSession,\n setIsAuthenticated,\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 setUser,\n setSession,\n setIsAuthenticated,\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","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","children","user","setUser","useState","session","setSession","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","withValidation","refresh","undefined","then","fetchUser","me","value","useMemo","React","default","createElement","Context","Provider"],"mappings":"
|
|
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 Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { withValidation } from '../../utils';\nimport useSdk from './useSdk';\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 // 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 children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = 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 oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\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 // 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 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 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","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","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","withValidation","refresh","undefined","then","fetchUser","me","value","useMemo","React","default","createElement","Context","Provider"],"mappings":"kQA8C6C,EAC3CA,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,yBAAwB,EACxBC,iBAAgB,EAChBC,eAAc,EACdC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,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,WAAWR,GAC/CqB,EAAsBC,UAAO,GAE7BC,EAAMC,EAAAA,QAAO,CACjB/B,YACAC,UACAI,gBACAC,cACAF,wBACAG,aACAC,6BACAC,uCACAC,oBACAC,qBAGFqB,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,GAAOvB,IAAeqB,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCnB,GAAiB,GAEjBc,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,EAAAA,aAAY,KAE3BP,EAAiBE,UACrBF,EAAiBE,SAAU,EAE3BlB,GAAoB,GACpBwB,EAAAA,eAAenB,aAAA,EAAAA,EAAKoB,QAApBD,MAA6BE,GAAW,GAAMC,MAAK,KACjD3B,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEuB,EAAYL,EAAAA,aAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBpB,GAAiB,GACjB0B,EAAAA,eAAenB,EAAIwB,GAAnBL,GAAyBG,MAAK,KAC5B7B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEEyB,EAAQC,EAAAA,SACZ,KAAO,CACLH,YACAxC,OACAS,gBACAoB,cAAeA,EAAcC,QAC7BI,eACA/B,UACAI,kBACAI,mBACAE,gBACAe,iBAAkBA,EAAiBE,QACnC3C,YACAC,UACAC,gBACAC,aACAK,6BACAC,uCACAC,oBACAI,UACAG,aACAI,qBACAH,SACAY,SAEF,CACEuB,EACAxC,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB3C,EACAC,EACAC,EACAC,EACAM,EACAC,EACAI,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO2B,EAAAC,QAAAC,cAACC,UAAQC,SAAQ,CAACN,MAAOA,GAAQ3C,EAA4B"}
|
package/dist/cjs/constants.js
CHANGED
|
@@ -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.
|
|
1
|
+
"use strict";const e="undefined"!=typeof window;exports.IS_BROWSER=e,exports.baseHeaders={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.20.1"};
|
|
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,
|
|
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}};
|
|
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 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 isAuthenticated,\n };\n};\n\nexport default useSession;\n"],"names":["session","isSessionLoading","isOidcLoading","fetchSession","isSessionFetched","isAuthenticated","useContext","isLoading","useRef","useMemo","current","shouldFetchSession","useEffect","sessionToken"],"mappings":"wIAGmB,KACjB,MAAMA,QACJA,EAAOC,
|
|
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,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{withValidation as a}from"../../utils.js";import c from"./useSdk.js";const u=({projectId:u,baseUrl:d="",baseStaticUrl:h="",baseCdnUrl:f="",sessionTokenViaCookie:
|
|
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{withValidation as a}from"../../utils.js";import c from"./useSdk.js";const u=({projectId:u,baseUrl:d="",baseStaticUrl:h="",baseCdnUrl:f="",sessionTokenViaCookie:l=!1,persistTokens:k=!0,autoRefresh:U=!0,oidcConfig:g,storeLastAuthenticatedUser:m=!0,keepLastAuthenticatedUserAfterLogout:C=!1,refreshCookieName:p="",getExternalToken:L,children:A})=>{const[S,b]=t(),[T,j]=t(),[I,v]=t(),[x,N]=t(!1),[E,F]=t(!1),[R,V]=t(!1),[y,O]=t(!!g),P=s(!1),q=c({projectId:u,baseUrl:d,persistTokens:k,autoRefresh:U,sessionTokenViaCookie:l,oidcConfig:g,storeLastAuthenticatedUser:m,keepLastAuthenticatedUserAfterLogout:C,refreshCookieName:p,getExternalToken:L});r((()=>{if(q){const e=q.onSessionTokenChange(j),t=q.onUserChange(b),s=q.onIsAuthenticatedChange(N),r=q.onClaimsChange(v);return()=>{e(),t(),s(),r()}}}),[q]);const w=s(!1),z=s(!1);r((()=>{q&&g&&!P.current&&(P.current=!0,q.oidc.finishLoginIfNeed().finally((()=>{O(!1),w.current=!0})))}),[]);const B=o((()=>{w.current||(w.current=!0,V(!0),a(null==q?void 0:q.refresh)(void 0,!0).then((()=>{V(!1)})))}),[q]),D=o((()=>{z.current||(z.current=!0,F(!0),a(q.me)().then((()=>{F(!1)})))}),[q]),G=n((()=>({fetchUser:D,user:S,isUserLoading:E,isUserFetched:z.current,fetchSession:B,session:T,isAuthenticated:x,isSessionLoading:R,isOidcLoading:y,isSessionFetched:w.current,projectId:u,baseUrl:d,baseStaticUrl:h,baseCdnUrl:f,storeLastAuthenticatedUser:m,keepLastAuthenticatedUserAfterLogout:C,refreshCookieName:p,setUser:b,setSession:j,setIsAuthenticated:N,claims:I,sdk:q})),[D,S,E,z.current,B,T,x,R,y,w.current,u,d,h,f,C,p,b,j,N,I,q]);return e.createElement(i.Provider,{value:G},A)};export{u 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 { CookieConfig, OidcConfig } from '@descope/web-js-sdk';\nimport Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { withValidation } from '../../utils';\nimport useSdk from './useSdk';\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 // 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 children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = undefined,\n children = undefined,\n}) => {\n const [user, setUser] = useState<User>();\n const [session, setSession] = useState<string>();\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 oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\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\n return () => {\n unsubscribeSessionToken();\n unsubscribeUser();\n unsubscribeIsAuthenticated();\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 // 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 setUser,\n setSession,\n setIsAuthenticated,\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 setUser,\n setSession,\n setIsAuthenticated,\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","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","children","user","setUser","useState","session","setSession","isAuthenticated","setIsAuthenticated","isUserLoading","setIsUserLoading","isSessionLoading","setIsSessionLoading","isOidcLoading","setIsOidcLoading","isOidcFinishedLogin","useRef","sdk","useSdk","useEffect","unsubscribeSessionToken","onSessionTokenChange","unsubscribeUser","onUserChange","unsubscribeIsAuthenticated","onIsAuthenticatedChange","isSessionFetched","isUserFetched","current","oidc","finishLoginIfNeed","finally","fetchSession","useCallback","withValidation","refresh","undefined","then","fetchUser","me","value","useMemo","React","createElement","Context","Provider"],"mappings":"
|
|
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 Context from '../../hooks/Context';\nimport { IContext, User } from '../../types';\nimport { withValidation } from '../../utils';\nimport useSdk from './useSdk';\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 // 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 children?: React.ReactNode;\n}\n\nconst AuthProvider: FC<IAuthProviderProps> = ({\n projectId,\n baseUrl = '',\n baseStaticUrl = '',\n baseCdnUrl = '',\n sessionTokenViaCookie = false,\n persistTokens = true,\n autoRefresh = true,\n oidcConfig = undefined,\n storeLastAuthenticatedUser = true,\n keepLastAuthenticatedUserAfterLogout = false,\n refreshCookieName = '',\n getExternalToken = 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 oidcConfig,\n storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout,\n refreshCookieName,\n getExternalToken,\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 // 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 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 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","persistTokens","autoRefresh","oidcConfig","storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout","refreshCookieName","getExternalToken","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","withValidation","refresh","undefined","then","fetchUser","me","value","useMemo","React","createElement","Context","Provider"],"mappings":"8MA8CM,MAAAA,EAAuC,EAC3CC,YACAC,UAAU,GACVC,gBAAgB,GAChBC,aAAa,GACbC,yBAAwB,EACxBC,iBAAgB,EAChBC,eAAc,EACdC,aACAC,8BAA6B,EAC7BC,wCAAuC,EACvCC,oBAAoB,GACpBC,mBACAC,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,IAAWR,GAC/CqB,EAAsBC,GAAO,GAE7BC,EAAMC,EAAO,CACjB/B,YACAC,UACAI,gBACAC,cACAF,wBACAG,aACAC,6BACAC,uCACAC,oBACAC,qBAGFqB,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,GAAOvB,IAAeqB,EAAoBe,UAC5Cf,EAAoBe,SAAU,EAC9Bb,EAAIc,KAAKC,oBAAoBC,SAAQ,KACnCnB,GAAiB,GAEjBc,EAAiBE,SAAU,CAAI,IAElC,GACA,IAEH,MAAMI,EAAeC,GAAY,KAE3BP,EAAiBE,UACrBF,EAAiBE,SAAU,EAE3BlB,GAAoB,GACpBwB,EAAenB,aAAA,EAAAA,EAAKoB,QAApBD,MAA6BE,GAAW,GAAMC,MAAK,KACjD3B,GAAoB,EAAM,IAC1B,GACD,CAACK,IAEEuB,EAAYL,GAAY,KAExBN,EAAcC,UAClBD,EAAcC,SAAU,EAExBpB,GAAiB,GACjB0B,EAAenB,EAAIwB,GAAnBL,GAAyBG,MAAK,KAC5B7B,GAAiB,EAAM,IACvB,GACD,CAACO,IAEEyB,EAAQC,GACZ,KAAO,CACLH,YACAxC,OACAS,gBACAoB,cAAeA,EAAcC,QAC7BI,eACA/B,UACAI,kBACAI,mBACAE,gBACAe,iBAAkBA,EAAiBE,QACnC3C,YACAC,UACAC,gBACAC,aACAK,6BACAC,uCACAC,oBACAI,UACAG,aACAI,qBACAH,SACAY,SAEF,CACEuB,EACAxC,EACAS,EACAoB,EAAcC,QACdI,EACA/B,EACAI,EACAI,EACAE,EACAe,EAAiBE,QACjB3C,EACAC,EACAC,EACAC,EACAM,EACAC,EACAI,EACAG,EACAI,EACAH,EACAY,IAGJ,OAAO2B,EAAAC,cAACC,EAAQC,SAAQ,CAACL,MAAOA,GAAQ3C,EAA4B"}
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.
|
|
1
|
+
const e={"x-descope-sdk-name":"react","x-descope-sdk-version":"2.20.1"},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
|
|
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};
|
|
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 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 isAuthenticated,\n };\n};\n\nexport default useSession;\n"],"names":["useSession","session","isSessionLoading","isOidcLoading","fetchSession","isSessionFetched","isAuthenticated","useContext","isLoading","useRef","useMemo","current","shouldFetchSession","useEffect","sessionToken"],"mappings":"0FAGM,MAAAA,EAAa,KACjB,MAAMC,QACJA,EAAOC,
|
|
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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1970,6 +1970,7 @@ declare const createSdkWrapper: <P extends {
|
|
|
1970
1970
|
}) & {
|
|
1971
1971
|
onSessionTokenChange: (cb: (data: string) => void) => () => any[];
|
|
1972
1972
|
onUserChange: (cb: (data: _1.UserResponse) => void) => () => any[];
|
|
1973
|
+
onClaimsChange: (cb: (data: _1.Claims) => void) => () => any[];
|
|
1973
1974
|
onIsAuthenticatedChange: (cb: (isAuthenticated: boolean) => void) => () => any[];
|
|
1974
1975
|
}) & {
|
|
1975
1976
|
getLastUserLoginId: () => string;
|
|
@@ -2082,6 +2083,7 @@ declare const useDescope: () => Sdk;
|
|
|
2082
2083
|
declare const useSession: () => {
|
|
2083
2084
|
isSessionLoading: boolean;
|
|
2084
2085
|
sessionToken: string;
|
|
2086
|
+
claims: _1.Claims;
|
|
2085
2087
|
isAuthenticated: boolean;
|
|
2086
2088
|
};
|
|
2087
2089
|
|