@contember/react-client-tenant 2.1.0-alpha.23 → 2.1.0-alpha.25
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/dist/development/src/components/idp/IDP.cjs +1 -1
- package/dist/development/src/components/idp/IDP.cjs.map +1 -1
- package/dist/development/src/components/idp/IDP.js +1 -1
- package/dist/development/src/components/idp/IDP.js.map +1 -1
- package/dist/development/src/internal/hooks/useHandleIDPResponse.cjs +3 -3
- package/dist/development/src/internal/hooks/useHandleIDPResponse.cjs.map +1 -1
- package/dist/development/src/internal/hooks/useHandleIDPResponse.js +3 -3
- package/dist/development/src/internal/hooks/useHandleIDPResponse.js.map +1 -1
- package/dist/production/src/components/idp/IDP.cjs +1 -1
- package/dist/production/src/components/idp/IDP.cjs.map +1 -1
- package/dist/production/src/components/idp/IDP.js +1 -1
- package/dist/production/src/components/idp/IDP.js.map +1 -1
- package/dist/production/src/internal/hooks/useHandleIDPResponse.cjs +3 -3
- package/dist/production/src/internal/hooks/useHandleIDPResponse.cjs.map +1 -1
- package/dist/production/src/internal/hooks/useHandleIDPResponse.js +3 -3
- package/dist/production/src/internal/hooks/useHandleIDPResponse.js.map +1 -1
- package/dist/types/internal/hooks/useHandleIDPResponse.d.ts +2 -1
- package/dist/types/internal/hooks/useHandleIDPResponse.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/idp/IDP.tsx +1 -1
- package/src/internal/hooks/useHandleIDPResponse.ts +4 -3
|
@@ -21,7 +21,7 @@ const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redi
|
|
|
21
21
|
}
|
|
22
22
|
return { type: "nothing" };
|
|
23
23
|
});
|
|
24
|
-
useHandleIDPResponse.useHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration });
|
|
24
|
+
useHandleIDPResponse.useHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration, redirectUrl });
|
|
25
25
|
const initRedirect = useInitIDPRedirect.useInitIDPRedirect({ setState, redirectUrl });
|
|
26
26
|
const isFirstRender = React.useRef(true);
|
|
27
27
|
React.useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IDP.cjs","sources":["../../../../../../packages/react-client-tenant/src/components/idp/IDP.tsx"],"sourcesContent":["import { ReactNode, useEffect, useMemo, useRef, useState } from 'react'\nimport { IDPMethodsContextProvider, IDPStateContextProvider } from '../../contexts'\nimport { IDPInitError, IDPResponseError, IDPStateValue } from '../../types/idp'\nimport { useHandleIDPResponse } from '../../internal/hooks/useHandleIDPResponse'\nimport { useIDPAutoInitProvider } from '../../internal/hooks/useIDPAutoInit'\nimport { useInitIDPRedirect } from '../../internal/hooks/useInitIDPRedirect'\n\nexport interface IDPProps {\n\tchildren: ReactNode\n\tonLogin?: () => void\n\tonInitError?: (error: IDPInitError) => void\n\tonResponseError?: (error: IDPResponseError) => void\n\texpiration?: number\n\tredirectUrl?: string\n}\n\nexport const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redirectUrl }: IDPProps) => {\n\tconst hasOauthResponse = useMemo(() => {\n\t\tconst params = new URLSearchParams(window.location.search)\n\t\treturn params.has('state') && (params.has('code') || params.has('id_token'))\n\t}, [])\n\n\tconst autoInit = useIDPAutoInitProvider()\n\tconst [state, setState] = useState<IDPStateValue>(() => {\n\t\tif (hasOauthResponse) {\n\t\t\treturn { type: 'processing_response' }\n\t\t}\n\t\tif (autoInit) {\n\t\t\treturn { type: 'processing_init' }\n\t\t}\n\t\treturn { type: 'nothing' }\n\t})\n\tuseHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration: expiration })\n\n\tconst initRedirect = useInitIDPRedirect({ setState, redirectUrl })\n\n\tconst isFirstRender = useRef(true)\n\tuseEffect(() => {\n\t\tif (!autoInit) {\n\t\t\treturn\n\t\t}\n\t\tif (!isFirstRender.current) {\n\t\t\treturn\n\t\t}\n\t\tisFirstRender.current = false\n\t\tinitRedirect({ provider: autoInit })\n\t}, [autoInit, initRedirect])\n\n\tuseEffect(() => {\n\t\tif (state.type === 'init_failed' && onInitError) {\n\t\t\tonInitError(state.error)\n\t\t}\n\t\tif (state.type === 'response_failed' && onResponseError) {\n\t\t\tonResponseError(state.error)\n\t\t}\n\t}, [onInitError, onResponseError, state])\n\n\n\treturn (\n\t\t<IDPStateContextProvider.Provider value={state}>\n\t\t\t<IDPMethodsContextProvider.Provider value={{ initRedirect }}>\n\t\t\t\t{children}\n\t\t\t</IDPMethodsContextProvider.Provider>\n\t\t</IDPStateContextProvider.Provider>\n\t)\n\n}\n"],"names":["useMemo","useIDPAutoInitProvider","useState","useHandleIDPResponse","useInitIDPRedirect","useRef","useEffect","jsxDEV","IDPStateContextProvider","IDPMethodsContextProvider","this"],"mappings":";;;;;;;;AAgBa,MAAA,MAAM,CAAC,EAAE,UAAU,iBAAiB,aAAa,SAAS,YAAY,kBAA4B;AACxG,QAAA,mBAAmBA,MAAAA,QAAQ,MAAM;AACtC,UAAM,SAAS,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAClD,WAAA,OAAO,IAAI,OAAO,MAAM,OAAO,IAAI,MAAM,KAAK,OAAO,IAAI,UAAU;AAAA,EAC3E,GAAG,EAAE;AAEL,QAAM,WAAWC,eAAAA,uBAAuB;AACxC,QAAM,CAAC,OAAO,QAAQ,IAAIC,eAAwB,MAAM;AACvD,QAAI,kBAAkB;AACd,aAAA,EAAE,MAAM,sBAAsB;AAAA,IAAA;AAEtC,QAAI,UAAU;AACN,aAAA,EAAE,MAAM,kBAAkB;AAAA,IAAA;AAE3B,WAAA,EAAE,MAAM,UAAU;AAAA,EAAA,CACzB;AACDC,
|
|
1
|
+
{"version":3,"file":"IDP.cjs","sources":["../../../../../../packages/react-client-tenant/src/components/idp/IDP.tsx"],"sourcesContent":["import { ReactNode, useEffect, useMemo, useRef, useState } from 'react'\nimport { IDPMethodsContextProvider, IDPStateContextProvider } from '../../contexts'\nimport { IDPInitError, IDPResponseError, IDPStateValue } from '../../types/idp'\nimport { useHandleIDPResponse } from '../../internal/hooks/useHandleIDPResponse'\nimport { useIDPAutoInitProvider } from '../../internal/hooks/useIDPAutoInit'\nimport { useInitIDPRedirect } from '../../internal/hooks/useInitIDPRedirect'\n\nexport interface IDPProps {\n\tchildren: ReactNode\n\tonLogin?: () => void\n\tonInitError?: (error: IDPInitError) => void\n\tonResponseError?: (error: IDPResponseError) => void\n\texpiration?: number\n\tredirectUrl?: string\n}\n\nexport const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redirectUrl }: IDPProps) => {\n\tconst hasOauthResponse = useMemo(() => {\n\t\tconst params = new URLSearchParams(window.location.search)\n\t\treturn params.has('state') && (params.has('code') || params.has('id_token'))\n\t}, [])\n\n\tconst autoInit = useIDPAutoInitProvider()\n\tconst [state, setState] = useState<IDPStateValue>(() => {\n\t\tif (hasOauthResponse) {\n\t\t\treturn { type: 'processing_response' }\n\t\t}\n\t\tif (autoInit) {\n\t\t\treturn { type: 'processing_init' }\n\t\t}\n\t\treturn { type: 'nothing' }\n\t})\n\tuseHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration: expiration, redirectUrl })\n\n\tconst initRedirect = useInitIDPRedirect({ setState, redirectUrl })\n\n\tconst isFirstRender = useRef(true)\n\tuseEffect(() => {\n\t\tif (!autoInit) {\n\t\t\treturn\n\t\t}\n\t\tif (!isFirstRender.current) {\n\t\t\treturn\n\t\t}\n\t\tisFirstRender.current = false\n\t\tinitRedirect({ provider: autoInit })\n\t}, [autoInit, initRedirect])\n\n\tuseEffect(() => {\n\t\tif (state.type === 'init_failed' && onInitError) {\n\t\t\tonInitError(state.error)\n\t\t}\n\t\tif (state.type === 'response_failed' && onResponseError) {\n\t\t\tonResponseError(state.error)\n\t\t}\n\t}, [onInitError, onResponseError, state])\n\n\n\treturn (\n\t\t<IDPStateContextProvider.Provider value={state}>\n\t\t\t<IDPMethodsContextProvider.Provider value={{ initRedirect }}>\n\t\t\t\t{children}\n\t\t\t</IDPMethodsContextProvider.Provider>\n\t\t</IDPStateContextProvider.Provider>\n\t)\n\n}\n"],"names":["useMemo","useIDPAutoInitProvider","useState","useHandleIDPResponse","useInitIDPRedirect","useRef","useEffect","jsxDEV","IDPStateContextProvider","IDPMethodsContextProvider","this"],"mappings":";;;;;;;;AAgBa,MAAA,MAAM,CAAC,EAAE,UAAU,iBAAiB,aAAa,SAAS,YAAY,kBAA4B;AACxG,QAAA,mBAAmBA,MAAAA,QAAQ,MAAM;AACtC,UAAM,SAAS,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAClD,WAAA,OAAO,IAAI,OAAO,MAAM,OAAO,IAAI,MAAM,KAAK,OAAO,IAAI,UAAU;AAAA,EAC3E,GAAG,EAAE;AAEL,QAAM,WAAWC,eAAAA,uBAAuB;AACxC,QAAM,CAAC,OAAO,QAAQ,IAAIC,eAAwB,MAAM;AACvD,QAAI,kBAAkB;AACd,aAAA,EAAE,MAAM,sBAAsB;AAAA,IAAA;AAEtC,QAAI,UAAU;AACN,aAAA,EAAE,MAAM,kBAAkB;AAAA,IAAA;AAE3B,WAAA,EAAE,MAAM,UAAU;AAAA,EAAA,CACzB;AACDC,uBAAA,qBAAqB,EAAE,kBAAkB,UAAU,SAAS,YAAwB,aAAa;AAEjG,QAAM,eAAeC,mBAAA,mBAAmB,EAAE,UAAU,aAAa;AAE3D,QAAA,gBAAgBC,aAAO,IAAI;AACjCC,QAAAA,UAAU,MAAM;AACf,QAAI,CAAC,UAAU;AACd;AAAA,IAAA;AAEG,QAAA,CAAC,cAAc,SAAS;AAC3B;AAAA,IAAA;AAED,kBAAc,UAAU;AACX,iBAAA,EAAE,UAAU,UAAU;AAAA,EAAA,GACjC,CAAC,UAAU,YAAY,CAAC;AAE3BA,QAAAA,UAAU,MAAM;AACX,QAAA,MAAM,SAAS,iBAAiB,aAAa;AAChD,kBAAY,MAAM,KAAK;AAAA,IAAA;AAEpB,QAAA,MAAM,SAAS,qBAAqB,iBAAiB;AACxD,sBAAgB,MAAM,KAAK;AAAA,IAAA;AAAA,EAE1B,GAAA,CAAC,aAAa,iBAAiB,KAAK,CAAC;AAGxC,SACEC,8BAAAA,OAAAC,SAAAA,wBAAwB,UAAxB,EAAiC,OAAO,OACxC,UAAAD,qCAACE,SAAAA,0BAA0B,UAA1B,EAAmC,OAAO,EAAE,aAAA,GAC3C,YADF,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAA,GAAAC,MAEA,EAHD,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAIA,GAAAA,MAAA;AAGF;;"}
|
|
@@ -19,7 +19,7 @@ const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redi
|
|
|
19
19
|
}
|
|
20
20
|
return { type: "nothing" };
|
|
21
21
|
});
|
|
22
|
-
useHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration });
|
|
22
|
+
useHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration, redirectUrl });
|
|
23
23
|
const initRedirect = useInitIDPRedirect({ setState, redirectUrl });
|
|
24
24
|
const isFirstRender = useRef(true);
|
|
25
25
|
useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IDP.js","sources":["../../../../../../packages/react-client-tenant/src/components/idp/IDP.tsx"],"sourcesContent":["import { ReactNode, useEffect, useMemo, useRef, useState } from 'react'\nimport { IDPMethodsContextProvider, IDPStateContextProvider } from '../../contexts'\nimport { IDPInitError, IDPResponseError, IDPStateValue } from '../../types/idp'\nimport { useHandleIDPResponse } from '../../internal/hooks/useHandleIDPResponse'\nimport { useIDPAutoInitProvider } from '../../internal/hooks/useIDPAutoInit'\nimport { useInitIDPRedirect } from '../../internal/hooks/useInitIDPRedirect'\n\nexport interface IDPProps {\n\tchildren: ReactNode\n\tonLogin?: () => void\n\tonInitError?: (error: IDPInitError) => void\n\tonResponseError?: (error: IDPResponseError) => void\n\texpiration?: number\n\tredirectUrl?: string\n}\n\nexport const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redirectUrl }: IDPProps) => {\n\tconst hasOauthResponse = useMemo(() => {\n\t\tconst params = new URLSearchParams(window.location.search)\n\t\treturn params.has('state') && (params.has('code') || params.has('id_token'))\n\t}, [])\n\n\tconst autoInit = useIDPAutoInitProvider()\n\tconst [state, setState] = useState<IDPStateValue>(() => {\n\t\tif (hasOauthResponse) {\n\t\t\treturn { type: 'processing_response' }\n\t\t}\n\t\tif (autoInit) {\n\t\t\treturn { type: 'processing_init' }\n\t\t}\n\t\treturn { type: 'nothing' }\n\t})\n\tuseHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration: expiration })\n\n\tconst initRedirect = useInitIDPRedirect({ setState, redirectUrl })\n\n\tconst isFirstRender = useRef(true)\n\tuseEffect(() => {\n\t\tif (!autoInit) {\n\t\t\treturn\n\t\t}\n\t\tif (!isFirstRender.current) {\n\t\t\treturn\n\t\t}\n\t\tisFirstRender.current = false\n\t\tinitRedirect({ provider: autoInit })\n\t}, [autoInit, initRedirect])\n\n\tuseEffect(() => {\n\t\tif (state.type === 'init_failed' && onInitError) {\n\t\t\tonInitError(state.error)\n\t\t}\n\t\tif (state.type === 'response_failed' && onResponseError) {\n\t\t\tonResponseError(state.error)\n\t\t}\n\t}, [onInitError, onResponseError, state])\n\n\n\treturn (\n\t\t<IDPStateContextProvider.Provider value={state}>\n\t\t\t<IDPMethodsContextProvider.Provider value={{ initRedirect }}>\n\t\t\t\t{children}\n\t\t\t</IDPMethodsContextProvider.Provider>\n\t\t</IDPStateContextProvider.Provider>\n\t)\n\n}\n"],"names":["this"],"mappings":";;;;;;AAgBa,MAAA,MAAM,CAAC,EAAE,UAAU,iBAAiB,aAAa,SAAS,YAAY,kBAA4B;AACxG,QAAA,mBAAmB,QAAQ,MAAM;AACtC,UAAM,SAAS,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAClD,WAAA,OAAO,IAAI,OAAO,MAAM,OAAO,IAAI,MAAM,KAAK,OAAO,IAAI,UAAU;AAAA,EAC3E,GAAG,EAAE;AAEL,QAAM,WAAW,uBAAuB;AACxC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,MAAM;AACvD,QAAI,kBAAkB;AACd,aAAA,EAAE,MAAM,sBAAsB;AAAA,IAAA;AAEtC,QAAI,UAAU;AACN,aAAA,EAAE,MAAM,kBAAkB;AAAA,IAAA;AAE3B,WAAA,EAAE,MAAM,UAAU;AAAA,EAAA,CACzB;AACD,uBAAqB,EAAE,kBAAkB,UAAU,SAAS,YAAwB;
|
|
1
|
+
{"version":3,"file":"IDP.js","sources":["../../../../../../packages/react-client-tenant/src/components/idp/IDP.tsx"],"sourcesContent":["import { ReactNode, useEffect, useMemo, useRef, useState } from 'react'\nimport { IDPMethodsContextProvider, IDPStateContextProvider } from '../../contexts'\nimport { IDPInitError, IDPResponseError, IDPStateValue } from '../../types/idp'\nimport { useHandleIDPResponse } from '../../internal/hooks/useHandleIDPResponse'\nimport { useIDPAutoInitProvider } from '../../internal/hooks/useIDPAutoInit'\nimport { useInitIDPRedirect } from '../../internal/hooks/useInitIDPRedirect'\n\nexport interface IDPProps {\n\tchildren: ReactNode\n\tonLogin?: () => void\n\tonInitError?: (error: IDPInitError) => void\n\tonResponseError?: (error: IDPResponseError) => void\n\texpiration?: number\n\tredirectUrl?: string\n}\n\nexport const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redirectUrl }: IDPProps) => {\n\tconst hasOauthResponse = useMemo(() => {\n\t\tconst params = new URLSearchParams(window.location.search)\n\t\treturn params.has('state') && (params.has('code') || params.has('id_token'))\n\t}, [])\n\n\tconst autoInit = useIDPAutoInitProvider()\n\tconst [state, setState] = useState<IDPStateValue>(() => {\n\t\tif (hasOauthResponse) {\n\t\t\treturn { type: 'processing_response' }\n\t\t}\n\t\tif (autoInit) {\n\t\t\treturn { type: 'processing_init' }\n\t\t}\n\t\treturn { type: 'nothing' }\n\t})\n\tuseHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration: expiration, redirectUrl })\n\n\tconst initRedirect = useInitIDPRedirect({ setState, redirectUrl })\n\n\tconst isFirstRender = useRef(true)\n\tuseEffect(() => {\n\t\tif (!autoInit) {\n\t\t\treturn\n\t\t}\n\t\tif (!isFirstRender.current) {\n\t\t\treturn\n\t\t}\n\t\tisFirstRender.current = false\n\t\tinitRedirect({ provider: autoInit })\n\t}, [autoInit, initRedirect])\n\n\tuseEffect(() => {\n\t\tif (state.type === 'init_failed' && onInitError) {\n\t\t\tonInitError(state.error)\n\t\t}\n\t\tif (state.type === 'response_failed' && onResponseError) {\n\t\t\tonResponseError(state.error)\n\t\t}\n\t}, [onInitError, onResponseError, state])\n\n\n\treturn (\n\t\t<IDPStateContextProvider.Provider value={state}>\n\t\t\t<IDPMethodsContextProvider.Provider value={{ initRedirect }}>\n\t\t\t\t{children}\n\t\t\t</IDPMethodsContextProvider.Provider>\n\t\t</IDPStateContextProvider.Provider>\n\t)\n\n}\n"],"names":["this"],"mappings":";;;;;;AAgBa,MAAA,MAAM,CAAC,EAAE,UAAU,iBAAiB,aAAa,SAAS,YAAY,kBAA4B;AACxG,QAAA,mBAAmB,QAAQ,MAAM;AACtC,UAAM,SAAS,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAClD,WAAA,OAAO,IAAI,OAAO,MAAM,OAAO,IAAI,MAAM,KAAK,OAAO,IAAI,UAAU;AAAA,EAC3E,GAAG,EAAE;AAEL,QAAM,WAAW,uBAAuB;AACxC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,MAAM;AACvD,QAAI,kBAAkB;AACd,aAAA,EAAE,MAAM,sBAAsB;AAAA,IAAA;AAEtC,QAAI,UAAU;AACN,aAAA,EAAE,MAAM,kBAAkB;AAAA,IAAA;AAE3B,WAAA,EAAE,MAAM,UAAU;AAAA,EAAA,CACzB;AACD,uBAAqB,EAAE,kBAAkB,UAAU,SAAS,YAAwB,aAAa;AAEjG,QAAM,eAAe,mBAAmB,EAAE,UAAU,aAAa;AAE3D,QAAA,gBAAgB,OAAO,IAAI;AACjC,YAAU,MAAM;AACf,QAAI,CAAC,UAAU;AACd;AAAA,IAAA;AAEG,QAAA,CAAC,cAAc,SAAS;AAC3B;AAAA,IAAA;AAED,kBAAc,UAAU;AACX,iBAAA,EAAE,UAAU,UAAU;AAAA,EAAA,GACjC,CAAC,UAAU,YAAY,CAAC;AAE3B,YAAU,MAAM;AACX,QAAA,MAAM,SAAS,iBAAiB,aAAa;AAChD,kBAAY,MAAM,KAAK;AAAA,IAAA;AAEpB,QAAA,MAAM,SAAS,qBAAqB,iBAAiB;AACxD,sBAAgB,MAAM,KAAK;AAAA,IAAA;AAAA,EAE1B,GAAA,CAAC,aAAa,iBAAiB,KAAK,CAAC;AAGxC,SACE,uBAAA,wBAAwB,UAAxB,EAAiC,OAAO,OACxC,UAAA,uBAAC,0BAA0B,UAA1B,EAAmC,OAAO,EAAE,aAAA,GAC3C,YADF,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAA,GAAAA,MAEA,EAHD,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAIA,GAAAA,MAAA;AAGF;"}
|
|
@@ -10,7 +10,7 @@ const headers = {
|
|
|
10
10
|
"X-Contember-Token-Path": "data.mutation.result.token"
|
|
11
11
|
};
|
|
12
12
|
const DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60;
|
|
13
|
-
const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse }) => {
|
|
13
|
+
const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse, redirectUrl }) => {
|
|
14
14
|
const idpSignIn = useSignInIdpMutation.useSignInIDPMutation({ headers });
|
|
15
15
|
const setSessionToken = reactClient.useSetSessionToken();
|
|
16
16
|
const firstRenderRef = React.useRef(true);
|
|
@@ -30,7 +30,7 @@ const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION,
|
|
|
30
30
|
const response = await idpSignIn({
|
|
31
31
|
data: {
|
|
32
32
|
url: window.location.href,
|
|
33
|
-
redirectUrl: getBaseHref.getBaseHref(),
|
|
33
|
+
redirectUrl: redirectUrl || getBaseHref.getBaseHref(),
|
|
34
34
|
sessionData: idpState.sessionData
|
|
35
35
|
},
|
|
36
36
|
identityProvider: idpState.provider,
|
|
@@ -45,7 +45,7 @@ const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION,
|
|
|
45
45
|
redirectToBackLink();
|
|
46
46
|
}
|
|
47
47
|
})();
|
|
48
|
-
}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink]);
|
|
48
|
+
}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink, redirectUrl]);
|
|
49
49
|
};
|
|
50
50
|
exports.useHandleIDPResponse = useHandleIDPResponse;
|
|
51
51
|
//# sourceMappingURL=useHandleIDPResponse.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHandleIDPResponse.cjs","sources":["../../../../../../packages/react-client-tenant/src/internal/hooks/useHandleIDPResponse.ts"],"sourcesContent":["import { SetStateAction, useEffect, useRef } from 'react'\nimport { useSetSessionToken } from '@contember/react-client'\nimport { useIDPStateStore } from './useIDPStateStore'\nimport { getBaseHref } from '../utils/getBaseHref'\nimport { IDPStateValue } from '../../types/idp'\nimport { useSignInIDPMutation } from '../../hooks'\nimport { useRedirectToBacklinkCallback } from './useRedirectToBacklink'\n\nexport interface UseHandleIDPResponseProps {\n\tonLogin?: () => void\n\texpiration?: number\n\n\tsetState: (state: SetStateAction<IDPStateValue>) => void\n\thasOauthResponse: boolean\n}\n\nconst headers = {\n\t'X-Contember-Token-Path': 'data.mutation.result.token',\n}\n\nconst DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60 // 14 days\n\nexport const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse }: UseHandleIDPResponseProps): void => {\n\tconst idpSignIn = useSignInIDPMutation({ headers })\n\tconst setSessionToken = useSetSessionToken()\n\n\tconst firstRenderRef = useRef(true)\n\n\tconst { get: loadIdpState } = useIDPStateStore()\n\tconst redirectToBackLink = useRedirectToBacklinkCallback()\n\n\tuseEffect(() => {\n\t\tif (!hasOauthResponse || !firstRenderRef.current) {\n\t\t\treturn\n\t\t}\n\t\tfirstRenderRef.current = false\n\t\t;(async () => {\n\t\t\tconst idpState = loadIdpState()\n\t\t\tif (!idpState) {\n\t\t\t\tsetState({ type: 'response_failed', error: 'INVALID_LOCAL_STATE' })\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst response = await idpSignIn({\n\t\t\t\tdata: {\n\t\t\t\t\turl: window.location.href,\n\t\t\t\t\tredirectUrl: getBaseHref(),\n\t\t\t\t\tsessionData: idpState.sessionData,\n\t\t\t\t},\n\t\t\t\tidentityProvider: idpState.provider,\n\t\t\t\texpiration,\n\t\t\t})\n\t\t\tif (!response.ok) {\n\t\t\t\tsetState({ type: 'response_failed', error: response.error || 'UNKNOWN_ERROR' })\n\t\t\t} else {\n\t\t\t\tsetSessionToken(response.result.token)\n\t\t\t\tsetState({ type: 'success' })\n\n\t\t\t\tonLogin?.()\n\t\t\t\tredirectToBackLink()\n\t\t\t}\n\t\t})()\n\t}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink])\n}\n"],"names":["useSignInIDPMutation","useSetSessionToken","useRef","useIDPStateStore","useRedirectToBacklinkCallback","useEffect","getBaseHref"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"useHandleIDPResponse.cjs","sources":["../../../../../../packages/react-client-tenant/src/internal/hooks/useHandleIDPResponse.ts"],"sourcesContent":["import { SetStateAction, useEffect, useRef } from 'react'\nimport { useSetSessionToken } from '@contember/react-client'\nimport { useIDPStateStore } from './useIDPStateStore'\nimport { getBaseHref } from '../utils/getBaseHref'\nimport { IDPStateValue } from '../../types/idp'\nimport { useSignInIDPMutation } from '../../hooks'\nimport { useRedirectToBacklinkCallback } from './useRedirectToBacklink'\n\nexport interface UseHandleIDPResponseProps {\n\tonLogin?: () => void\n\texpiration?: number\n\n\tsetState: (state: SetStateAction<IDPStateValue>) => void\n\thasOauthResponse: boolean\n\tredirectUrl?: string\n}\n\nconst headers = {\n\t'X-Contember-Token-Path': 'data.mutation.result.token',\n}\n\nconst DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60 // 14 days\n\nexport const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse, redirectUrl }: UseHandleIDPResponseProps): void => {\n\tconst idpSignIn = useSignInIDPMutation({ headers })\n\tconst setSessionToken = useSetSessionToken()\n\n\tconst firstRenderRef = useRef(true)\n\n\tconst { get: loadIdpState } = useIDPStateStore()\n\tconst redirectToBackLink = useRedirectToBacklinkCallback()\n\n\tuseEffect(() => {\n\t\tif (!hasOauthResponse || !firstRenderRef.current) {\n\t\t\treturn\n\t\t}\n\t\tfirstRenderRef.current = false\n\t\t;(async () => {\n\t\t\tconst idpState = loadIdpState()\n\t\t\tif (!idpState) {\n\t\t\t\tsetState({ type: 'response_failed', error: 'INVALID_LOCAL_STATE' })\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst response = await idpSignIn({\n\t\t\t\tdata: {\n\t\t\t\t\turl: window.location.href,\n\t\t\t\t\tredirectUrl: redirectUrl || getBaseHref(),\n\t\t\t\t\tsessionData: idpState.sessionData,\n\t\t\t\t},\n\t\t\t\tidentityProvider: idpState.provider,\n\t\t\t\texpiration,\n\t\t\t})\n\t\t\tif (!response.ok) {\n\t\t\t\tsetState({ type: 'response_failed', error: response.error || 'UNKNOWN_ERROR' })\n\t\t\t} else {\n\t\t\t\tsetSessionToken(response.result.token)\n\t\t\t\tsetState({ type: 'success' })\n\n\t\t\t\tonLogin?.()\n\t\t\t\tredirectToBackLink()\n\t\t\t}\n\t\t})()\n\t}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink, redirectUrl])\n}\n"],"names":["useSignInIDPMutation","useSetSessionToken","useRef","useIDPStateStore","useRedirectToBacklinkCallback","useEffect","getBaseHref"],"mappings":";;;;;;;;AAiBA,MAAM,UAAU;AAAA,EACf,0BAA0B;AAC3B;AAEA,MAAM,2BAA2B,KAAK,KAAK;AAE9B,MAAA,uBAAuB,CAAC,EAAE,SAAS,aAAa,0BAA0B,UAAU,kBAAkB,kBAAmD;AACrK,QAAM,YAAYA,qBAAAA,qBAAqB,EAAE,SAAS;AAClD,QAAM,kBAAkBC,YAAAA,mBAAmB;AAErC,QAAA,iBAAiBC,aAAO,IAAI;AAElC,QAAM,EAAE,KAAK,aAAa,IAAIC,kCAAiB;AAC/C,QAAM,qBAAqBC,sBAAAA,8BAA8B;AAEzDC,QAAAA,UAAU,MAAM;AACf,QAAI,CAAC,oBAAoB,CAAC,eAAe,SAAS;AACjD;AAAA,IAAA;AAED,mBAAe,UAAU;AACxB,KAAC,YAAY;AACb,YAAM,WAAW,aAAa;AAC9B,UAAI,CAAC,UAAU;AACd,iBAAS,EAAE,MAAM,mBAAmB,OAAO,uBAAuB;AAClE;AAAA,MAAA;AAGK,YAAA,WAAW,MAAM,UAAU;AAAA,QAChC,MAAM;AAAA,UACL,KAAK,OAAO,SAAS;AAAA,UACrB,aAAa,eAAeC,wBAAY;AAAA,UACxC,aAAa,SAAS;AAAA,QACvB;AAAA,QACA,kBAAkB,SAAS;AAAA,QAC3B;AAAA,MAAA,CACA;AACG,UAAA,CAAC,SAAS,IAAI;AACjB,iBAAS,EAAE,MAAM,mBAAmB,OAAO,SAAS,SAAS,iBAAiB;AAAA,MAAA,OACxE;AACU,wBAAA,SAAS,OAAO,KAAK;AAC5B,iBAAA,EAAE,MAAM,WAAW;AAElB,kBAAA;AACS,2BAAA;AAAA,MAAA;AAAA,IACpB,GACE;AAAA,EACJ,GAAG,CAAC,WAAW,SAAS,iBAAiB,kBAAkB,cAAc,YAAY,UAAU,oBAAoB,WAAW,CAAC;AAChI;;"}
|
|
@@ -8,7 +8,7 @@ const headers = {
|
|
|
8
8
|
"X-Contember-Token-Path": "data.mutation.result.token"
|
|
9
9
|
};
|
|
10
10
|
const DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60;
|
|
11
|
-
const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse }) => {
|
|
11
|
+
const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse, redirectUrl }) => {
|
|
12
12
|
const idpSignIn = useSignInIDPMutation({ headers });
|
|
13
13
|
const setSessionToken = useSetSessionToken();
|
|
14
14
|
const firstRenderRef = useRef(true);
|
|
@@ -28,7 +28,7 @@ const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION,
|
|
|
28
28
|
const response = await idpSignIn({
|
|
29
29
|
data: {
|
|
30
30
|
url: window.location.href,
|
|
31
|
-
redirectUrl: getBaseHref(),
|
|
31
|
+
redirectUrl: redirectUrl || getBaseHref(),
|
|
32
32
|
sessionData: idpState.sessionData
|
|
33
33
|
},
|
|
34
34
|
identityProvider: idpState.provider,
|
|
@@ -43,7 +43,7 @@ const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION,
|
|
|
43
43
|
redirectToBackLink();
|
|
44
44
|
}
|
|
45
45
|
})();
|
|
46
|
-
}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink]);
|
|
46
|
+
}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink, redirectUrl]);
|
|
47
47
|
};
|
|
48
48
|
export {
|
|
49
49
|
useHandleIDPResponse
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHandleIDPResponse.js","sources":["../../../../../../packages/react-client-tenant/src/internal/hooks/useHandleIDPResponse.ts"],"sourcesContent":["import { SetStateAction, useEffect, useRef } from 'react'\nimport { useSetSessionToken } from '@contember/react-client'\nimport { useIDPStateStore } from './useIDPStateStore'\nimport { getBaseHref } from '../utils/getBaseHref'\nimport { IDPStateValue } from '../../types/idp'\nimport { useSignInIDPMutation } from '../../hooks'\nimport { useRedirectToBacklinkCallback } from './useRedirectToBacklink'\n\nexport interface UseHandleIDPResponseProps {\n\tonLogin?: () => void\n\texpiration?: number\n\n\tsetState: (state: SetStateAction<IDPStateValue>) => void\n\thasOauthResponse: boolean\n}\n\nconst headers = {\n\t'X-Contember-Token-Path': 'data.mutation.result.token',\n}\n\nconst DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60 // 14 days\n\nexport const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse }: UseHandleIDPResponseProps): void => {\n\tconst idpSignIn = useSignInIDPMutation({ headers })\n\tconst setSessionToken = useSetSessionToken()\n\n\tconst firstRenderRef = useRef(true)\n\n\tconst { get: loadIdpState } = useIDPStateStore()\n\tconst redirectToBackLink = useRedirectToBacklinkCallback()\n\n\tuseEffect(() => {\n\t\tif (!hasOauthResponse || !firstRenderRef.current) {\n\t\t\treturn\n\t\t}\n\t\tfirstRenderRef.current = false\n\t\t;(async () => {\n\t\t\tconst idpState = loadIdpState()\n\t\t\tif (!idpState) {\n\t\t\t\tsetState({ type: 'response_failed', error: 'INVALID_LOCAL_STATE' })\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst response = await idpSignIn({\n\t\t\t\tdata: {\n\t\t\t\t\turl: window.location.href,\n\t\t\t\t\tredirectUrl: getBaseHref(),\n\t\t\t\t\tsessionData: idpState.sessionData,\n\t\t\t\t},\n\t\t\t\tidentityProvider: idpState.provider,\n\t\t\t\texpiration,\n\t\t\t})\n\t\t\tif (!response.ok) {\n\t\t\t\tsetState({ type: 'response_failed', error: response.error || 'UNKNOWN_ERROR' })\n\t\t\t} else {\n\t\t\t\tsetSessionToken(response.result.token)\n\t\t\t\tsetState({ type: 'success' })\n\n\t\t\t\tonLogin?.()\n\t\t\t\tredirectToBackLink()\n\t\t\t}\n\t\t})()\n\t}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink])\n}\n"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"useHandleIDPResponse.js","sources":["../../../../../../packages/react-client-tenant/src/internal/hooks/useHandleIDPResponse.ts"],"sourcesContent":["import { SetStateAction, useEffect, useRef } from 'react'\nimport { useSetSessionToken } from '@contember/react-client'\nimport { useIDPStateStore } from './useIDPStateStore'\nimport { getBaseHref } from '../utils/getBaseHref'\nimport { IDPStateValue } from '../../types/idp'\nimport { useSignInIDPMutation } from '../../hooks'\nimport { useRedirectToBacklinkCallback } from './useRedirectToBacklink'\n\nexport interface UseHandleIDPResponseProps {\n\tonLogin?: () => void\n\texpiration?: number\n\n\tsetState: (state: SetStateAction<IDPStateValue>) => void\n\thasOauthResponse: boolean\n\tredirectUrl?: string\n}\n\nconst headers = {\n\t'X-Contember-Token-Path': 'data.mutation.result.token',\n}\n\nconst DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60 // 14 days\n\nexport const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse, redirectUrl }: UseHandleIDPResponseProps): void => {\n\tconst idpSignIn = useSignInIDPMutation({ headers })\n\tconst setSessionToken = useSetSessionToken()\n\n\tconst firstRenderRef = useRef(true)\n\n\tconst { get: loadIdpState } = useIDPStateStore()\n\tconst redirectToBackLink = useRedirectToBacklinkCallback()\n\n\tuseEffect(() => {\n\t\tif (!hasOauthResponse || !firstRenderRef.current) {\n\t\t\treturn\n\t\t}\n\t\tfirstRenderRef.current = false\n\t\t;(async () => {\n\t\t\tconst idpState = loadIdpState()\n\t\t\tif (!idpState) {\n\t\t\t\tsetState({ type: 'response_failed', error: 'INVALID_LOCAL_STATE' })\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst response = await idpSignIn({\n\t\t\t\tdata: {\n\t\t\t\t\turl: window.location.href,\n\t\t\t\t\tredirectUrl: redirectUrl || getBaseHref(),\n\t\t\t\t\tsessionData: idpState.sessionData,\n\t\t\t\t},\n\t\t\t\tidentityProvider: idpState.provider,\n\t\t\t\texpiration,\n\t\t\t})\n\t\t\tif (!response.ok) {\n\t\t\t\tsetState({ type: 'response_failed', error: response.error || 'UNKNOWN_ERROR' })\n\t\t\t} else {\n\t\t\t\tsetSessionToken(response.result.token)\n\t\t\t\tsetState({ type: 'success' })\n\n\t\t\t\tonLogin?.()\n\t\t\t\tredirectToBackLink()\n\t\t\t}\n\t\t})()\n\t}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink, redirectUrl])\n}\n"],"names":[],"mappings":";;;;;;AAiBA,MAAM,UAAU;AAAA,EACf,0BAA0B;AAC3B;AAEA,MAAM,2BAA2B,KAAK,KAAK;AAE9B,MAAA,uBAAuB,CAAC,EAAE,SAAS,aAAa,0BAA0B,UAAU,kBAAkB,kBAAmD;AACrK,QAAM,YAAY,qBAAqB,EAAE,SAAS;AAClD,QAAM,kBAAkB,mBAAmB;AAErC,QAAA,iBAAiB,OAAO,IAAI;AAElC,QAAM,EAAE,KAAK,aAAa,IAAI,iBAAiB;AAC/C,QAAM,qBAAqB,8BAA8B;AAEzD,YAAU,MAAM;AACf,QAAI,CAAC,oBAAoB,CAAC,eAAe,SAAS;AACjD;AAAA,IAAA;AAED,mBAAe,UAAU;AACxB,KAAC,YAAY;AACb,YAAM,WAAW,aAAa;AAC9B,UAAI,CAAC,UAAU;AACd,iBAAS,EAAE,MAAM,mBAAmB,OAAO,uBAAuB;AAClE;AAAA,MAAA;AAGK,YAAA,WAAW,MAAM,UAAU;AAAA,QAChC,MAAM;AAAA,UACL,KAAK,OAAO,SAAS;AAAA,UACrB,aAAa,eAAe,YAAY;AAAA,UACxC,aAAa,SAAS;AAAA,QACvB;AAAA,QACA,kBAAkB,SAAS;AAAA,QAC3B;AAAA,MAAA,CACA;AACG,UAAA,CAAC,SAAS,IAAI;AACjB,iBAAS,EAAE,MAAM,mBAAmB,OAAO,SAAS,SAAS,iBAAiB;AAAA,MAAA,OACxE;AACU,wBAAA,SAAS,OAAO,KAAK;AAC5B,iBAAA,EAAE,MAAM,WAAW;AAElB,kBAAA;AACS,2BAAA;AAAA,MAAA;AAAA,IACpB,GACE;AAAA,EACJ,GAAG,CAAC,WAAW,SAAS,iBAAiB,kBAAkB,cAAc,YAAY,UAAU,oBAAoB,WAAW,CAAC;AAChI;"}
|
|
@@ -21,7 +21,7 @@ const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redi
|
|
|
21
21
|
}
|
|
22
22
|
return { type: "nothing" };
|
|
23
23
|
});
|
|
24
|
-
useHandleIDPResponse.useHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration });
|
|
24
|
+
useHandleIDPResponse.useHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration, redirectUrl });
|
|
25
25
|
const initRedirect = useInitIDPRedirect.useInitIDPRedirect({ setState, redirectUrl });
|
|
26
26
|
const isFirstRender = React.useRef(true);
|
|
27
27
|
React.useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IDP.cjs","sources":["../../../../../../packages/react-client-tenant/src/components/idp/IDP.tsx"],"sourcesContent":["import { ReactNode, useEffect, useMemo, useRef, useState } from 'react'\nimport { IDPMethodsContextProvider, IDPStateContextProvider } from '../../contexts'\nimport { IDPInitError, IDPResponseError, IDPStateValue } from '../../types/idp'\nimport { useHandleIDPResponse } from '../../internal/hooks/useHandleIDPResponse'\nimport { useIDPAutoInitProvider } from '../../internal/hooks/useIDPAutoInit'\nimport { useInitIDPRedirect } from '../../internal/hooks/useInitIDPRedirect'\n\nexport interface IDPProps {\n\tchildren: ReactNode\n\tonLogin?: () => void\n\tonInitError?: (error: IDPInitError) => void\n\tonResponseError?: (error: IDPResponseError) => void\n\texpiration?: number\n\tredirectUrl?: string\n}\n\nexport const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redirectUrl }: IDPProps) => {\n\tconst hasOauthResponse = useMemo(() => {\n\t\tconst params = new URLSearchParams(window.location.search)\n\t\treturn params.has('state') && (params.has('code') || params.has('id_token'))\n\t}, [])\n\n\tconst autoInit = useIDPAutoInitProvider()\n\tconst [state, setState] = useState<IDPStateValue>(() => {\n\t\tif (hasOauthResponse) {\n\t\t\treturn { type: 'processing_response' }\n\t\t}\n\t\tif (autoInit) {\n\t\t\treturn { type: 'processing_init' }\n\t\t}\n\t\treturn { type: 'nothing' }\n\t})\n\tuseHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration: expiration })\n\n\tconst initRedirect = useInitIDPRedirect({ setState, redirectUrl })\n\n\tconst isFirstRender = useRef(true)\n\tuseEffect(() => {\n\t\tif (!autoInit) {\n\t\t\treturn\n\t\t}\n\t\tif (!isFirstRender.current) {\n\t\t\treturn\n\t\t}\n\t\tisFirstRender.current = false\n\t\tinitRedirect({ provider: autoInit })\n\t}, [autoInit, initRedirect])\n\n\tuseEffect(() => {\n\t\tif (state.type === 'init_failed' && onInitError) {\n\t\t\tonInitError(state.error)\n\t\t}\n\t\tif (state.type === 'response_failed' && onResponseError) {\n\t\t\tonResponseError(state.error)\n\t\t}\n\t}, [onInitError, onResponseError, state])\n\n\n\treturn (\n\t\t<IDPStateContextProvider.Provider value={state}>\n\t\t\t<IDPMethodsContextProvider.Provider value={{ initRedirect }}>\n\t\t\t\t{children}\n\t\t\t</IDPMethodsContextProvider.Provider>\n\t\t</IDPStateContextProvider.Provider>\n\t)\n\n}\n"],"names":["useMemo","useIDPAutoInitProvider","useState","useHandleIDPResponse","useInitIDPRedirect","useRef","useEffect","jsx","IDPStateContextProvider","IDPMethodsContextProvider"],"mappings":";;;;;;;;AAgBa,MAAA,MAAM,CAAC,EAAE,UAAU,iBAAiB,aAAa,SAAS,YAAY,kBAA4B;AACxG,QAAA,mBAAmBA,MAAAA,QAAQ,MAAM;AACtC,UAAM,SAAS,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAClD,WAAA,OAAO,IAAI,OAAO,MAAM,OAAO,IAAI,MAAM,KAAK,OAAO,IAAI,UAAU;AAAA,EAC3E,GAAG,EAAE;AAEL,QAAM,WAAWC,eAAAA,uBAAuB;AACxC,QAAM,CAAC,OAAO,QAAQ,IAAIC,eAAwB,MAAM;AACvD,QAAI,kBAAkB;AACd,aAAA,EAAE,MAAM,sBAAsB;AAAA,IAAA;AAEtC,QAAI,UAAU;AACN,aAAA,EAAE,MAAM,kBAAkB;AAAA,IAAA;AAE3B,WAAA,EAAE,MAAM,UAAU;AAAA,EAAA,CACzB;AACDC,
|
|
1
|
+
{"version":3,"file":"IDP.cjs","sources":["../../../../../../packages/react-client-tenant/src/components/idp/IDP.tsx"],"sourcesContent":["import { ReactNode, useEffect, useMemo, useRef, useState } from 'react'\nimport { IDPMethodsContextProvider, IDPStateContextProvider } from '../../contexts'\nimport { IDPInitError, IDPResponseError, IDPStateValue } from '../../types/idp'\nimport { useHandleIDPResponse } from '../../internal/hooks/useHandleIDPResponse'\nimport { useIDPAutoInitProvider } from '../../internal/hooks/useIDPAutoInit'\nimport { useInitIDPRedirect } from '../../internal/hooks/useInitIDPRedirect'\n\nexport interface IDPProps {\n\tchildren: ReactNode\n\tonLogin?: () => void\n\tonInitError?: (error: IDPInitError) => void\n\tonResponseError?: (error: IDPResponseError) => void\n\texpiration?: number\n\tredirectUrl?: string\n}\n\nexport const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redirectUrl }: IDPProps) => {\n\tconst hasOauthResponse = useMemo(() => {\n\t\tconst params = new URLSearchParams(window.location.search)\n\t\treturn params.has('state') && (params.has('code') || params.has('id_token'))\n\t}, [])\n\n\tconst autoInit = useIDPAutoInitProvider()\n\tconst [state, setState] = useState<IDPStateValue>(() => {\n\t\tif (hasOauthResponse) {\n\t\t\treturn { type: 'processing_response' }\n\t\t}\n\t\tif (autoInit) {\n\t\t\treturn { type: 'processing_init' }\n\t\t}\n\t\treturn { type: 'nothing' }\n\t})\n\tuseHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration: expiration, redirectUrl })\n\n\tconst initRedirect = useInitIDPRedirect({ setState, redirectUrl })\n\n\tconst isFirstRender = useRef(true)\n\tuseEffect(() => {\n\t\tif (!autoInit) {\n\t\t\treturn\n\t\t}\n\t\tif (!isFirstRender.current) {\n\t\t\treturn\n\t\t}\n\t\tisFirstRender.current = false\n\t\tinitRedirect({ provider: autoInit })\n\t}, [autoInit, initRedirect])\n\n\tuseEffect(() => {\n\t\tif (state.type === 'init_failed' && onInitError) {\n\t\t\tonInitError(state.error)\n\t\t}\n\t\tif (state.type === 'response_failed' && onResponseError) {\n\t\t\tonResponseError(state.error)\n\t\t}\n\t}, [onInitError, onResponseError, state])\n\n\n\treturn (\n\t\t<IDPStateContextProvider.Provider value={state}>\n\t\t\t<IDPMethodsContextProvider.Provider value={{ initRedirect }}>\n\t\t\t\t{children}\n\t\t\t</IDPMethodsContextProvider.Provider>\n\t\t</IDPStateContextProvider.Provider>\n\t)\n\n}\n"],"names":["useMemo","useIDPAutoInitProvider","useState","useHandleIDPResponse","useInitIDPRedirect","useRef","useEffect","jsx","IDPStateContextProvider","IDPMethodsContextProvider"],"mappings":";;;;;;;;AAgBa,MAAA,MAAM,CAAC,EAAE,UAAU,iBAAiB,aAAa,SAAS,YAAY,kBAA4B;AACxG,QAAA,mBAAmBA,MAAAA,QAAQ,MAAM;AACtC,UAAM,SAAS,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAClD,WAAA,OAAO,IAAI,OAAO,MAAM,OAAO,IAAI,MAAM,KAAK,OAAO,IAAI,UAAU;AAAA,EAC3E,GAAG,EAAE;AAEL,QAAM,WAAWC,eAAAA,uBAAuB;AACxC,QAAM,CAAC,OAAO,QAAQ,IAAIC,eAAwB,MAAM;AACvD,QAAI,kBAAkB;AACd,aAAA,EAAE,MAAM,sBAAsB;AAAA,IAAA;AAEtC,QAAI,UAAU;AACN,aAAA,EAAE,MAAM,kBAAkB;AAAA,IAAA;AAE3B,WAAA,EAAE,MAAM,UAAU;AAAA,EAAA,CACzB;AACDC,uBAAA,qBAAqB,EAAE,kBAAkB,UAAU,SAAS,YAAwB,aAAa;AAEjG,QAAM,eAAeC,mBAAA,mBAAmB,EAAE,UAAU,aAAa;AAE3D,QAAA,gBAAgBC,aAAO,IAAI;AACjCC,QAAAA,UAAU,MAAM;AACf,QAAI,CAAC,UAAU;AACd;AAAA,IAAA;AAEG,QAAA,CAAC,cAAc,SAAS;AAC3B;AAAA,IAAA;AAED,kBAAc,UAAU;AACX,iBAAA,EAAE,UAAU,UAAU;AAAA,EAAA,GACjC,CAAC,UAAU,YAAY,CAAC;AAE3BA,QAAAA,UAAU,MAAM;AACX,QAAA,MAAM,SAAS,iBAAiB,aAAa;AAChD,kBAAY,MAAM,KAAK;AAAA,IAAA;AAEpB,QAAA,MAAM,SAAS,qBAAqB,iBAAiB;AACxD,sBAAgB,MAAM,KAAK;AAAA,IAAA;AAAA,EAE1B,GAAA,CAAC,aAAa,iBAAiB,KAAK,CAAC;AAGxC,SACEC,2BAAAA,IAAAC,SAAAA,wBAAwB,UAAxB,EAAiC,OAAO,OACxC,UAAAD,2BAAAA,IAACE,SAAAA,0BAA0B,UAA1B,EAAmC,OAAO,EAAE,aAAa,GACxD,SACF,CAAA,GACD;AAGF;;"}
|
|
@@ -19,7 +19,7 @@ const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redi
|
|
|
19
19
|
}
|
|
20
20
|
return { type: "nothing" };
|
|
21
21
|
});
|
|
22
|
-
useHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration });
|
|
22
|
+
useHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration, redirectUrl });
|
|
23
23
|
const initRedirect = useInitIDPRedirect({ setState, redirectUrl });
|
|
24
24
|
const isFirstRender = useRef(true);
|
|
25
25
|
useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IDP.js","sources":["../../../../../../packages/react-client-tenant/src/components/idp/IDP.tsx"],"sourcesContent":["import { ReactNode, useEffect, useMemo, useRef, useState } from 'react'\nimport { IDPMethodsContextProvider, IDPStateContextProvider } from '../../contexts'\nimport { IDPInitError, IDPResponseError, IDPStateValue } from '../../types/idp'\nimport { useHandleIDPResponse } from '../../internal/hooks/useHandleIDPResponse'\nimport { useIDPAutoInitProvider } from '../../internal/hooks/useIDPAutoInit'\nimport { useInitIDPRedirect } from '../../internal/hooks/useInitIDPRedirect'\n\nexport interface IDPProps {\n\tchildren: ReactNode\n\tonLogin?: () => void\n\tonInitError?: (error: IDPInitError) => void\n\tonResponseError?: (error: IDPResponseError) => void\n\texpiration?: number\n\tredirectUrl?: string\n}\n\nexport const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redirectUrl }: IDPProps) => {\n\tconst hasOauthResponse = useMemo(() => {\n\t\tconst params = new URLSearchParams(window.location.search)\n\t\treturn params.has('state') && (params.has('code') || params.has('id_token'))\n\t}, [])\n\n\tconst autoInit = useIDPAutoInitProvider()\n\tconst [state, setState] = useState<IDPStateValue>(() => {\n\t\tif (hasOauthResponse) {\n\t\t\treturn { type: 'processing_response' }\n\t\t}\n\t\tif (autoInit) {\n\t\t\treturn { type: 'processing_init' }\n\t\t}\n\t\treturn { type: 'nothing' }\n\t})\n\tuseHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration: expiration })\n\n\tconst initRedirect = useInitIDPRedirect({ setState, redirectUrl })\n\n\tconst isFirstRender = useRef(true)\n\tuseEffect(() => {\n\t\tif (!autoInit) {\n\t\t\treturn\n\t\t}\n\t\tif (!isFirstRender.current) {\n\t\t\treturn\n\t\t}\n\t\tisFirstRender.current = false\n\t\tinitRedirect({ provider: autoInit })\n\t}, [autoInit, initRedirect])\n\n\tuseEffect(() => {\n\t\tif (state.type === 'init_failed' && onInitError) {\n\t\t\tonInitError(state.error)\n\t\t}\n\t\tif (state.type === 'response_failed' && onResponseError) {\n\t\t\tonResponseError(state.error)\n\t\t}\n\t}, [onInitError, onResponseError, state])\n\n\n\treturn (\n\t\t<IDPStateContextProvider.Provider value={state}>\n\t\t\t<IDPMethodsContextProvider.Provider value={{ initRedirect }}>\n\t\t\t\t{children}\n\t\t\t</IDPMethodsContextProvider.Provider>\n\t\t</IDPStateContextProvider.Provider>\n\t)\n\n}\n"],"names":[],"mappings":";;;;;;AAgBa,MAAA,MAAM,CAAC,EAAE,UAAU,iBAAiB,aAAa,SAAS,YAAY,kBAA4B;AACxG,QAAA,mBAAmB,QAAQ,MAAM;AACtC,UAAM,SAAS,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAClD,WAAA,OAAO,IAAI,OAAO,MAAM,OAAO,IAAI,MAAM,KAAK,OAAO,IAAI,UAAU;AAAA,EAC3E,GAAG,EAAE;AAEL,QAAM,WAAW,uBAAuB;AACxC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,MAAM;AACvD,QAAI,kBAAkB;AACd,aAAA,EAAE,MAAM,sBAAsB;AAAA,IAAA;AAEtC,QAAI,UAAU;AACN,aAAA,EAAE,MAAM,kBAAkB;AAAA,IAAA;AAE3B,WAAA,EAAE,MAAM,UAAU;AAAA,EAAA,CACzB;AACD,uBAAqB,EAAE,kBAAkB,UAAU,SAAS,YAAwB;
|
|
1
|
+
{"version":3,"file":"IDP.js","sources":["../../../../../../packages/react-client-tenant/src/components/idp/IDP.tsx"],"sourcesContent":["import { ReactNode, useEffect, useMemo, useRef, useState } from 'react'\nimport { IDPMethodsContextProvider, IDPStateContextProvider } from '../../contexts'\nimport { IDPInitError, IDPResponseError, IDPStateValue } from '../../types/idp'\nimport { useHandleIDPResponse } from '../../internal/hooks/useHandleIDPResponse'\nimport { useIDPAutoInitProvider } from '../../internal/hooks/useIDPAutoInit'\nimport { useInitIDPRedirect } from '../../internal/hooks/useInitIDPRedirect'\n\nexport interface IDPProps {\n\tchildren: ReactNode\n\tonLogin?: () => void\n\tonInitError?: (error: IDPInitError) => void\n\tonResponseError?: (error: IDPResponseError) => void\n\texpiration?: number\n\tredirectUrl?: string\n}\n\nexport const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redirectUrl }: IDPProps) => {\n\tconst hasOauthResponse = useMemo(() => {\n\t\tconst params = new URLSearchParams(window.location.search)\n\t\treturn params.has('state') && (params.has('code') || params.has('id_token'))\n\t}, [])\n\n\tconst autoInit = useIDPAutoInitProvider()\n\tconst [state, setState] = useState<IDPStateValue>(() => {\n\t\tif (hasOauthResponse) {\n\t\t\treturn { type: 'processing_response' }\n\t\t}\n\t\tif (autoInit) {\n\t\t\treturn { type: 'processing_init' }\n\t\t}\n\t\treturn { type: 'nothing' }\n\t})\n\tuseHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration: expiration, redirectUrl })\n\n\tconst initRedirect = useInitIDPRedirect({ setState, redirectUrl })\n\n\tconst isFirstRender = useRef(true)\n\tuseEffect(() => {\n\t\tif (!autoInit) {\n\t\t\treturn\n\t\t}\n\t\tif (!isFirstRender.current) {\n\t\t\treturn\n\t\t}\n\t\tisFirstRender.current = false\n\t\tinitRedirect({ provider: autoInit })\n\t}, [autoInit, initRedirect])\n\n\tuseEffect(() => {\n\t\tif (state.type === 'init_failed' && onInitError) {\n\t\t\tonInitError(state.error)\n\t\t}\n\t\tif (state.type === 'response_failed' && onResponseError) {\n\t\t\tonResponseError(state.error)\n\t\t}\n\t}, [onInitError, onResponseError, state])\n\n\n\treturn (\n\t\t<IDPStateContextProvider.Provider value={state}>\n\t\t\t<IDPMethodsContextProvider.Provider value={{ initRedirect }}>\n\t\t\t\t{children}\n\t\t\t</IDPMethodsContextProvider.Provider>\n\t\t</IDPStateContextProvider.Provider>\n\t)\n\n}\n"],"names":[],"mappings":";;;;;;AAgBa,MAAA,MAAM,CAAC,EAAE,UAAU,iBAAiB,aAAa,SAAS,YAAY,kBAA4B;AACxG,QAAA,mBAAmB,QAAQ,MAAM;AACtC,UAAM,SAAS,IAAI,gBAAgB,OAAO,SAAS,MAAM;AAClD,WAAA,OAAO,IAAI,OAAO,MAAM,OAAO,IAAI,MAAM,KAAK,OAAO,IAAI,UAAU;AAAA,EAC3E,GAAG,EAAE;AAEL,QAAM,WAAW,uBAAuB;AACxC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,MAAM;AACvD,QAAI,kBAAkB;AACd,aAAA,EAAE,MAAM,sBAAsB;AAAA,IAAA;AAEtC,QAAI,UAAU;AACN,aAAA,EAAE,MAAM,kBAAkB;AAAA,IAAA;AAE3B,WAAA,EAAE,MAAM,UAAU;AAAA,EAAA,CACzB;AACD,uBAAqB,EAAE,kBAAkB,UAAU,SAAS,YAAwB,aAAa;AAEjG,QAAM,eAAe,mBAAmB,EAAE,UAAU,aAAa;AAE3D,QAAA,gBAAgB,OAAO,IAAI;AACjC,YAAU,MAAM;AACf,QAAI,CAAC,UAAU;AACd;AAAA,IAAA;AAEG,QAAA,CAAC,cAAc,SAAS;AAC3B;AAAA,IAAA;AAED,kBAAc,UAAU;AACX,iBAAA,EAAE,UAAU,UAAU;AAAA,EAAA,GACjC,CAAC,UAAU,YAAY,CAAC;AAE3B,YAAU,MAAM;AACX,QAAA,MAAM,SAAS,iBAAiB,aAAa;AAChD,kBAAY,MAAM,KAAK;AAAA,IAAA;AAEpB,QAAA,MAAM,SAAS,qBAAqB,iBAAiB;AACxD,sBAAgB,MAAM,KAAK;AAAA,IAAA;AAAA,EAE1B,GAAA,CAAC,aAAa,iBAAiB,KAAK,CAAC;AAGxC,SACE,oBAAA,wBAAwB,UAAxB,EAAiC,OAAO,OACxC,UAAA,oBAAC,0BAA0B,UAA1B,EAAmC,OAAO,EAAE,aAAa,GACxD,SACF,CAAA,GACD;AAGF;"}
|
|
@@ -10,7 +10,7 @@ const headers = {
|
|
|
10
10
|
"X-Contember-Token-Path": "data.mutation.result.token"
|
|
11
11
|
};
|
|
12
12
|
const DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60;
|
|
13
|
-
const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse }) => {
|
|
13
|
+
const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse, redirectUrl }) => {
|
|
14
14
|
const idpSignIn = useSignInIdpMutation.useSignInIDPMutation({ headers });
|
|
15
15
|
const setSessionToken = reactClient.useSetSessionToken();
|
|
16
16
|
const firstRenderRef = React.useRef(true);
|
|
@@ -30,7 +30,7 @@ const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION,
|
|
|
30
30
|
const response = await idpSignIn({
|
|
31
31
|
data: {
|
|
32
32
|
url: window.location.href,
|
|
33
|
-
redirectUrl: getBaseHref.getBaseHref(),
|
|
33
|
+
redirectUrl: redirectUrl || getBaseHref.getBaseHref(),
|
|
34
34
|
sessionData: idpState.sessionData
|
|
35
35
|
},
|
|
36
36
|
identityProvider: idpState.provider,
|
|
@@ -45,7 +45,7 @@ const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION,
|
|
|
45
45
|
redirectToBackLink();
|
|
46
46
|
}
|
|
47
47
|
})();
|
|
48
|
-
}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink]);
|
|
48
|
+
}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink, redirectUrl]);
|
|
49
49
|
};
|
|
50
50
|
exports.useHandleIDPResponse = useHandleIDPResponse;
|
|
51
51
|
//# sourceMappingURL=useHandleIDPResponse.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHandleIDPResponse.cjs","sources":["../../../../../../packages/react-client-tenant/src/internal/hooks/useHandleIDPResponse.ts"],"sourcesContent":["import { SetStateAction, useEffect, useRef } from 'react'\nimport { useSetSessionToken } from '@contember/react-client'\nimport { useIDPStateStore } from './useIDPStateStore'\nimport { getBaseHref } from '../utils/getBaseHref'\nimport { IDPStateValue } from '../../types/idp'\nimport { useSignInIDPMutation } from '../../hooks'\nimport { useRedirectToBacklinkCallback } from './useRedirectToBacklink'\n\nexport interface UseHandleIDPResponseProps {\n\tonLogin?: () => void\n\texpiration?: number\n\n\tsetState: (state: SetStateAction<IDPStateValue>) => void\n\thasOauthResponse: boolean\n}\n\nconst headers = {\n\t'X-Contember-Token-Path': 'data.mutation.result.token',\n}\n\nconst DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60 // 14 days\n\nexport const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse }: UseHandleIDPResponseProps): void => {\n\tconst idpSignIn = useSignInIDPMutation({ headers })\n\tconst setSessionToken = useSetSessionToken()\n\n\tconst firstRenderRef = useRef(true)\n\n\tconst { get: loadIdpState } = useIDPStateStore()\n\tconst redirectToBackLink = useRedirectToBacklinkCallback()\n\n\tuseEffect(() => {\n\t\tif (!hasOauthResponse || !firstRenderRef.current) {\n\t\t\treturn\n\t\t}\n\t\tfirstRenderRef.current = false\n\t\t;(async () => {\n\t\t\tconst idpState = loadIdpState()\n\t\t\tif (!idpState) {\n\t\t\t\tsetState({ type: 'response_failed', error: 'INVALID_LOCAL_STATE' })\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst response = await idpSignIn({\n\t\t\t\tdata: {\n\t\t\t\t\turl: window.location.href,\n\t\t\t\t\tredirectUrl: getBaseHref(),\n\t\t\t\t\tsessionData: idpState.sessionData,\n\t\t\t\t},\n\t\t\t\tidentityProvider: idpState.provider,\n\t\t\t\texpiration,\n\t\t\t})\n\t\t\tif (!response.ok) {\n\t\t\t\tsetState({ type: 'response_failed', error: response.error || 'UNKNOWN_ERROR' })\n\t\t\t} else {\n\t\t\t\tsetSessionToken(response.result.token)\n\t\t\t\tsetState({ type: 'success' })\n\n\t\t\t\tonLogin?.()\n\t\t\t\tredirectToBackLink()\n\t\t\t}\n\t\t})()\n\t}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink])\n}\n"],"names":["useSignInIDPMutation","useSetSessionToken","useRef","useIDPStateStore","useRedirectToBacklinkCallback","useEffect","getBaseHref"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"useHandleIDPResponse.cjs","sources":["../../../../../../packages/react-client-tenant/src/internal/hooks/useHandleIDPResponse.ts"],"sourcesContent":["import { SetStateAction, useEffect, useRef } from 'react'\nimport { useSetSessionToken } from '@contember/react-client'\nimport { useIDPStateStore } from './useIDPStateStore'\nimport { getBaseHref } from '../utils/getBaseHref'\nimport { IDPStateValue } from '../../types/idp'\nimport { useSignInIDPMutation } from '../../hooks'\nimport { useRedirectToBacklinkCallback } from './useRedirectToBacklink'\n\nexport interface UseHandleIDPResponseProps {\n\tonLogin?: () => void\n\texpiration?: number\n\n\tsetState: (state: SetStateAction<IDPStateValue>) => void\n\thasOauthResponse: boolean\n\tredirectUrl?: string\n}\n\nconst headers = {\n\t'X-Contember-Token-Path': 'data.mutation.result.token',\n}\n\nconst DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60 // 14 days\n\nexport const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse, redirectUrl }: UseHandleIDPResponseProps): void => {\n\tconst idpSignIn = useSignInIDPMutation({ headers })\n\tconst setSessionToken = useSetSessionToken()\n\n\tconst firstRenderRef = useRef(true)\n\n\tconst { get: loadIdpState } = useIDPStateStore()\n\tconst redirectToBackLink = useRedirectToBacklinkCallback()\n\n\tuseEffect(() => {\n\t\tif (!hasOauthResponse || !firstRenderRef.current) {\n\t\t\treturn\n\t\t}\n\t\tfirstRenderRef.current = false\n\t\t;(async () => {\n\t\t\tconst idpState = loadIdpState()\n\t\t\tif (!idpState) {\n\t\t\t\tsetState({ type: 'response_failed', error: 'INVALID_LOCAL_STATE' })\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst response = await idpSignIn({\n\t\t\t\tdata: {\n\t\t\t\t\turl: window.location.href,\n\t\t\t\t\tredirectUrl: redirectUrl || getBaseHref(),\n\t\t\t\t\tsessionData: idpState.sessionData,\n\t\t\t\t},\n\t\t\t\tidentityProvider: idpState.provider,\n\t\t\t\texpiration,\n\t\t\t})\n\t\t\tif (!response.ok) {\n\t\t\t\tsetState({ type: 'response_failed', error: response.error || 'UNKNOWN_ERROR' })\n\t\t\t} else {\n\t\t\t\tsetSessionToken(response.result.token)\n\t\t\t\tsetState({ type: 'success' })\n\n\t\t\t\tonLogin?.()\n\t\t\t\tredirectToBackLink()\n\t\t\t}\n\t\t})()\n\t}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink, redirectUrl])\n}\n"],"names":["useSignInIDPMutation","useSetSessionToken","useRef","useIDPStateStore","useRedirectToBacklinkCallback","useEffect","getBaseHref"],"mappings":";;;;;;;;AAiBA,MAAM,UAAU;AAAA,EACf,0BAA0B;AAC3B;AAEA,MAAM,2BAA2B,KAAK,KAAK;AAE9B,MAAA,uBAAuB,CAAC,EAAE,SAAS,aAAa,0BAA0B,UAAU,kBAAkB,kBAAmD;AACrK,QAAM,YAAYA,qBAAAA,qBAAqB,EAAE,SAAS;AAClD,QAAM,kBAAkBC,YAAAA,mBAAmB;AAErC,QAAA,iBAAiBC,aAAO,IAAI;AAElC,QAAM,EAAE,KAAK,aAAa,IAAIC,kCAAiB;AAC/C,QAAM,qBAAqBC,sBAAAA,8BAA8B;AAEzDC,QAAAA,UAAU,MAAM;AACf,QAAI,CAAC,oBAAoB,CAAC,eAAe,SAAS;AACjD;AAAA,IAAA;AAED,mBAAe,UAAU;AACxB,KAAC,YAAY;AACb,YAAM,WAAW,aAAa;AAC9B,UAAI,CAAC,UAAU;AACd,iBAAS,EAAE,MAAM,mBAAmB,OAAO,uBAAuB;AAClE;AAAA,MAAA;AAGK,YAAA,WAAW,MAAM,UAAU;AAAA,QAChC,MAAM;AAAA,UACL,KAAK,OAAO,SAAS;AAAA,UACrB,aAAa,eAAeC,wBAAY;AAAA,UACxC,aAAa,SAAS;AAAA,QACvB;AAAA,QACA,kBAAkB,SAAS;AAAA,QAC3B;AAAA,MAAA,CACA;AACG,UAAA,CAAC,SAAS,IAAI;AACjB,iBAAS,EAAE,MAAM,mBAAmB,OAAO,SAAS,SAAS,iBAAiB;AAAA,MAAA,OACxE;AACU,wBAAA,SAAS,OAAO,KAAK;AAC5B,iBAAA,EAAE,MAAM,WAAW;AAElB,kBAAA;AACS,2BAAA;AAAA,MAAA;AAAA,IACpB,GACE;AAAA,EACJ,GAAG,CAAC,WAAW,SAAS,iBAAiB,kBAAkB,cAAc,YAAY,UAAU,oBAAoB,WAAW,CAAC;AAChI;;"}
|
|
@@ -8,7 +8,7 @@ const headers = {
|
|
|
8
8
|
"X-Contember-Token-Path": "data.mutation.result.token"
|
|
9
9
|
};
|
|
10
10
|
const DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60;
|
|
11
|
-
const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse }) => {
|
|
11
|
+
const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse, redirectUrl }) => {
|
|
12
12
|
const idpSignIn = useSignInIDPMutation({ headers });
|
|
13
13
|
const setSessionToken = useSetSessionToken();
|
|
14
14
|
const firstRenderRef = useRef(true);
|
|
@@ -28,7 +28,7 @@ const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION,
|
|
|
28
28
|
const response = await idpSignIn({
|
|
29
29
|
data: {
|
|
30
30
|
url: window.location.href,
|
|
31
|
-
redirectUrl: getBaseHref(),
|
|
31
|
+
redirectUrl: redirectUrl || getBaseHref(),
|
|
32
32
|
sessionData: idpState.sessionData
|
|
33
33
|
},
|
|
34
34
|
identityProvider: idpState.provider,
|
|
@@ -43,7 +43,7 @@ const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION,
|
|
|
43
43
|
redirectToBackLink();
|
|
44
44
|
}
|
|
45
45
|
})();
|
|
46
|
-
}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink]);
|
|
46
|
+
}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink, redirectUrl]);
|
|
47
47
|
};
|
|
48
48
|
export {
|
|
49
49
|
useHandleIDPResponse
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHandleIDPResponse.js","sources":["../../../../../../packages/react-client-tenant/src/internal/hooks/useHandleIDPResponse.ts"],"sourcesContent":["import { SetStateAction, useEffect, useRef } from 'react'\nimport { useSetSessionToken } from '@contember/react-client'\nimport { useIDPStateStore } from './useIDPStateStore'\nimport { getBaseHref } from '../utils/getBaseHref'\nimport { IDPStateValue } from '../../types/idp'\nimport { useSignInIDPMutation } from '../../hooks'\nimport { useRedirectToBacklinkCallback } from './useRedirectToBacklink'\n\nexport interface UseHandleIDPResponseProps {\n\tonLogin?: () => void\n\texpiration?: number\n\n\tsetState: (state: SetStateAction<IDPStateValue>) => void\n\thasOauthResponse: boolean\n}\n\nconst headers = {\n\t'X-Contember-Token-Path': 'data.mutation.result.token',\n}\n\nconst DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60 // 14 days\n\nexport const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse }: UseHandleIDPResponseProps): void => {\n\tconst idpSignIn = useSignInIDPMutation({ headers })\n\tconst setSessionToken = useSetSessionToken()\n\n\tconst firstRenderRef = useRef(true)\n\n\tconst { get: loadIdpState } = useIDPStateStore()\n\tconst redirectToBackLink = useRedirectToBacklinkCallback()\n\n\tuseEffect(() => {\n\t\tif (!hasOauthResponse || !firstRenderRef.current) {\n\t\t\treturn\n\t\t}\n\t\tfirstRenderRef.current = false\n\t\t;(async () => {\n\t\t\tconst idpState = loadIdpState()\n\t\t\tif (!idpState) {\n\t\t\t\tsetState({ type: 'response_failed', error: 'INVALID_LOCAL_STATE' })\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst response = await idpSignIn({\n\t\t\t\tdata: {\n\t\t\t\t\turl: window.location.href,\n\t\t\t\t\tredirectUrl: getBaseHref(),\n\t\t\t\t\tsessionData: idpState.sessionData,\n\t\t\t\t},\n\t\t\t\tidentityProvider: idpState.provider,\n\t\t\t\texpiration,\n\t\t\t})\n\t\t\tif (!response.ok) {\n\t\t\t\tsetState({ type: 'response_failed', error: response.error || 'UNKNOWN_ERROR' })\n\t\t\t} else {\n\t\t\t\tsetSessionToken(response.result.token)\n\t\t\t\tsetState({ type: 'success' })\n\n\t\t\t\tonLogin?.()\n\t\t\t\tredirectToBackLink()\n\t\t\t}\n\t\t})()\n\t}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink])\n}\n"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"useHandleIDPResponse.js","sources":["../../../../../../packages/react-client-tenant/src/internal/hooks/useHandleIDPResponse.ts"],"sourcesContent":["import { SetStateAction, useEffect, useRef } from 'react'\nimport { useSetSessionToken } from '@contember/react-client'\nimport { useIDPStateStore } from './useIDPStateStore'\nimport { getBaseHref } from '../utils/getBaseHref'\nimport { IDPStateValue } from '../../types/idp'\nimport { useSignInIDPMutation } from '../../hooks'\nimport { useRedirectToBacklinkCallback } from './useRedirectToBacklink'\n\nexport interface UseHandleIDPResponseProps {\n\tonLogin?: () => void\n\texpiration?: number\n\n\tsetState: (state: SetStateAction<IDPStateValue>) => void\n\thasOauthResponse: boolean\n\tredirectUrl?: string\n}\n\nconst headers = {\n\t'X-Contember-Token-Path': 'data.mutation.result.token',\n}\n\nconst DEFAULT_LOGIN_EXPIRATION = 14 * 24 * 60 // 14 days\n\nexport const useHandleIDPResponse = ({ onLogin, expiration = DEFAULT_LOGIN_EXPIRATION, setState, hasOauthResponse, redirectUrl }: UseHandleIDPResponseProps): void => {\n\tconst idpSignIn = useSignInIDPMutation({ headers })\n\tconst setSessionToken = useSetSessionToken()\n\n\tconst firstRenderRef = useRef(true)\n\n\tconst { get: loadIdpState } = useIDPStateStore()\n\tconst redirectToBackLink = useRedirectToBacklinkCallback()\n\n\tuseEffect(() => {\n\t\tif (!hasOauthResponse || !firstRenderRef.current) {\n\t\t\treturn\n\t\t}\n\t\tfirstRenderRef.current = false\n\t\t;(async () => {\n\t\t\tconst idpState = loadIdpState()\n\t\t\tif (!idpState) {\n\t\t\t\tsetState({ type: 'response_failed', error: 'INVALID_LOCAL_STATE' })\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst response = await idpSignIn({\n\t\t\t\tdata: {\n\t\t\t\t\turl: window.location.href,\n\t\t\t\t\tredirectUrl: redirectUrl || getBaseHref(),\n\t\t\t\t\tsessionData: idpState.sessionData,\n\t\t\t\t},\n\t\t\t\tidentityProvider: idpState.provider,\n\t\t\t\texpiration,\n\t\t\t})\n\t\t\tif (!response.ok) {\n\t\t\t\tsetState({ type: 'response_failed', error: response.error || 'UNKNOWN_ERROR' })\n\t\t\t} else {\n\t\t\t\tsetSessionToken(response.result.token)\n\t\t\t\tsetState({ type: 'success' })\n\n\t\t\t\tonLogin?.()\n\t\t\t\tredirectToBackLink()\n\t\t\t}\n\t\t})()\n\t}, [idpSignIn, onLogin, setSessionToken, hasOauthResponse, loadIdpState, expiration, setState, redirectToBackLink, redirectUrl])\n}\n"],"names":[],"mappings":";;;;;;AAiBA,MAAM,UAAU;AAAA,EACf,0BAA0B;AAC3B;AAEA,MAAM,2BAA2B,KAAK,KAAK;AAE9B,MAAA,uBAAuB,CAAC,EAAE,SAAS,aAAa,0BAA0B,UAAU,kBAAkB,kBAAmD;AACrK,QAAM,YAAY,qBAAqB,EAAE,SAAS;AAClD,QAAM,kBAAkB,mBAAmB;AAErC,QAAA,iBAAiB,OAAO,IAAI;AAElC,QAAM,EAAE,KAAK,aAAa,IAAI,iBAAiB;AAC/C,QAAM,qBAAqB,8BAA8B;AAEzD,YAAU,MAAM;AACf,QAAI,CAAC,oBAAoB,CAAC,eAAe,SAAS;AACjD;AAAA,IAAA;AAED,mBAAe,UAAU;AACxB,KAAC,YAAY;AACb,YAAM,WAAW,aAAa;AAC9B,UAAI,CAAC,UAAU;AACd,iBAAS,EAAE,MAAM,mBAAmB,OAAO,uBAAuB;AAClE;AAAA,MAAA;AAGK,YAAA,WAAW,MAAM,UAAU;AAAA,QAChC,MAAM;AAAA,UACL,KAAK,OAAO,SAAS;AAAA,UACrB,aAAa,eAAe,YAAY;AAAA,UACxC,aAAa,SAAS;AAAA,QACvB;AAAA,QACA,kBAAkB,SAAS;AAAA,QAC3B;AAAA,MAAA,CACA;AACG,UAAA,CAAC,SAAS,IAAI;AACjB,iBAAS,EAAE,MAAM,mBAAmB,OAAO,SAAS,SAAS,iBAAiB;AAAA,MAAA,OACxE;AACU,wBAAA,SAAS,OAAO,KAAK;AAC5B,iBAAA,EAAE,MAAM,WAAW;AAElB,kBAAA;AACS,2BAAA;AAAA,MAAA;AAAA,IACpB,GACE;AAAA,EACJ,GAAG,CAAC,WAAW,SAAS,iBAAiB,kBAAkB,cAAc,YAAY,UAAU,oBAAoB,WAAW,CAAC;AAChI;"}
|
|
@@ -5,6 +5,7 @@ export interface UseHandleIDPResponseProps {
|
|
|
5
5
|
expiration?: number;
|
|
6
6
|
setState: (state: SetStateAction<IDPStateValue>) => void;
|
|
7
7
|
hasOauthResponse: boolean;
|
|
8
|
+
redirectUrl?: string;
|
|
8
9
|
}
|
|
9
|
-
export declare const useHandleIDPResponse: ({ onLogin, expiration, setState, hasOauthResponse }: UseHandleIDPResponseProps) => void;
|
|
10
|
+
export declare const useHandleIDPResponse: ({ onLogin, expiration, setState, hasOauthResponse, redirectUrl }: UseHandleIDPResponseProps) => void;
|
|
10
11
|
//# sourceMappingURL=useHandleIDPResponse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHandleIDPResponse.d.ts","sourceRoot":"","sources":["../../../../src/internal/hooks/useHandleIDPResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAqB,MAAM,OAAO,CAAA;AAIzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAI/C,MAAM,WAAW,yBAAyB;IACzC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,aAAa,CAAC,KAAK,IAAI,CAAA;IACxD,gBAAgB,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"useHandleIDPResponse.d.ts","sourceRoot":"","sources":["../../../../src/internal/hooks/useHandleIDPResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAqB,MAAM,OAAO,CAAA;AAIzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAI/C,MAAM,WAAW,yBAAyB;IACzC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,aAAa,CAAC,KAAK,IAAI,CAAA;IACxD,gBAAgB,EAAE,OAAO,CAAA;IACzB,WAAW,CAAC,EAAE,MAAM,CAAA;CACpB;AAQD,eAAO,MAAM,oBAAoB,GAAI,kEAA6F,yBAAyB,KAAG,IAyC7J,CAAA"}
|