diff --git a/inst/dist/@cori-risi/contexts/ApiContextProvider.js b/inst/dist/@cori-risi/contexts/ApiContextProvider.js index f52f7543..8b0c161a 100644 --- a/inst/dist/@cori-risi/contexts/ApiContextProvider.js +++ b/inst/dist/@cori-risi/contexts/ApiContextProvider.js @@ -103,10 +103,10 @@ function ApiContextProvider(props) { // const [ authenticated_user, setAuthenticatedUser ] = useState(null); // const userState = useSelector(selectUser); // const dispatch = useDispatch(); - const [state, setState] = useState(Object.assign(Object.assign({}, initState), { setData })); + const [state, setState] = useState(Object.assign(Object.assign({}, initState), { baseURL: (!!props.baseURL) ? props.baseURL : BASE_URL, setData })); function setData(newData) { const currentState = state; - setState(Object.assign(Object.assign({}, currentState), { baseURL: (!!props.baseURL) ? props.baseURL : BASE_URL, data: Object.assign(Object.assign({}, currentState.data), newData), setData: setData })); + setState(Object.assign(Object.assign({}, currentState), { data: Object.assign(Object.assign({}, currentState.data), newData), setData: setData })); } if (!!props.baseURL && props.baseURL.length > 0) { apiClient.interceptors.request.use((config) => { diff --git a/inst/dist/@cori-risi/contexts/ApiContextProvider.js.map b/inst/dist/@cori-risi/contexts/ApiContextProvider.js.map index efa7e885..bd572cce 100644 --- a/inst/dist/@cori-risi/contexts/ApiContextProvider.js.map +++ b/inst/dist/@cori-risi/contexts/ApiContextProvider.js.map @@ -1 +1 @@ -{"version":3,"file":"ApiContextProvider.js","sources":["../../../../lib/@cori-risi/contexts/ApiContextProvider.tsx"],"sourcesContent":["import React, {\n createContext,\n ReactElement,\n // useContext,\n useEffect,\n useState\n} from \"react\";\nimport axios, { AxiosInstance } from 'axios';\nimport { AuthTokens, JWT } from \"@aws-amplify/auth\";\n// import { useDispatch, useSelector } from \"react-redux\";\n// import {\n// updateUserId,\n// updateUserName,\n// updateUserTokens,\n// selectUser\n// } from \"../features\";\n// import { User } from '../models';\n\nimport \"./styles/ApiContextProvider.css\";\nimport { User } from \"../models\";\n\nconst BASE_URL = \"https://cori-data-api.ruralinnovation.us/\"; // `${import.meta.env.VITE_CORI_DATA_API}`;\n// TODO: From now on must pass dev/prod API url in as param to ApiContextProvider because:\n// cori.data.api/lib/@cori-risi/cotexts/ApiContextProvider.tsx:22\n// const BASE_URL = `${import.meta.env.VITE_CORI_DATA_API}`;\n// ^^^^\n// SyntaxError: Cannot use 'import.meta' outside a module\n//\n\ntype AWSCredentials = {\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n expiration?: Date;\n};\n\ntype AuthSession = {\n tokens?: AuthTokens;\n credentials?: AWSCredentials;\n identityId?: string;\n userSub?: string;\n};\n\n/**\n * This is the interface/type of the [`ApiContext`](../variables/ApiContext.md).\n *\n * @property apiClient Axios client for RESTful services\n * @property authenticated `true` if the ApiContextProvider has established an authenticated session\n * @property authenticated_user the current user state if the ApiContextProvider has established an authenticated session\n * @property autoSignOut a function that can be called to terminate the current session (if using authentication)\n * @property baseURL Base URL for RESTful service\n * @property token id token retrieved from Cognito which is used in requests made by the `apiClient` (if using authentication)\n * @property data read-only data store\n * @property setData setter to update data store\n * @interface\n */\nexport interface ApiContextType {\n apiClient: AxiosInstance;\n authenticated: boolean;\n authenticated_user: User | null;\n autoSignOut: (() => void) | null;\n baseURL: string;\n token: JWT | null;\n data: any;\n setData: ((newData: any) => void);\n}\n\nconst apiClient: AxiosInstance = axios.create({\n baseURL: BASE_URL,\n headers: {\n 'Content-Type': 'application/json'\n },\n});\n\nconst apiData: any = {};\n\nconst initState: ApiContextType = {\n apiClient: apiClient,\n authenticated: false,\n authenticated_user: null,\n autoSignOut: null,\n baseURL: BASE_URL,\n token: null,\n data: {\n get: () => apiData,\n set: (newData: any) => {\n for (const d in newData) {\n if (newData.hasOwnProperty[d]) {\n apiData[d] = newData;\n }\n }\n }\n },\n setData: (newData: any) => {\n for (const d in newData) {\n if (newData.hasOwnProperty[d]) {\n apiData[d] = newData;\n }\n }\n }\n};\n\n/**\n * This is the data/api context for a React app that uses network requests to fetch data from either a RESTful\n * service backend or a GraphQL service backend (both are available in the\n * [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}). See\n * [`ApiContextType`](../interfaces/ApiContextType.md) for a list of props offered by this context.\n *\n * Note that GraphQL queries require a special client that can be instantiated by an additional context provider component\n * (i.e. [ApolloGraphQLProvider](https://github.com/ruralinnovation/amplify-bcat/tree/main/src/%40cori-risi/bcat/contexts){target=_blank}).\n *\n */\nexport const ApiContext = createContext(initState);\n\nlet hasAuthSession = false;\nlet hasAuthUser = false;\nlet hasAuthClient = false;\n\n/**\n * This component provides the API/data service context ([`ApiContext`](../variables/ApiContext.md)) to a React\n * application. The following example assumes that the `App` component has been configured by the\n * [`AmplifyContextProvider`](../functions/AmplifyContextProvider.md) to allow for authentication\n * with AWS Cognito, but this provider can also be used to setup an ApiContext with no authentication (by only using\n * the `baseURL` param/prop and disregarding the other props):\n *\n * ```ts\n * import {\n * withAuthenticator,\n * useAuthenticator,\n * UseAuthenticator, useTheme, Heading\n * } from '@aws-amplify/ui-react';\n * import { fetchAuthSession } from \"@aws-amplify/auth\";\n * import { getCurrentUser } from \"@aws-amplify/auth/cognito\";\n * import { AmplifyContext, ApiContextProvider } from \"@cori-risi/cori.data.api\";\n *\n * // ...\n *\n * const App = () => {\n *\n * const amplifyContext = useContext(AmplifyContext);\n * const authenticator: UseAuthenticator = useAuthenticator();\n *\n * // ...\n *\n * return (\n * \n * \n * \n * );\n * }\n *\n * export default withAuthenticator(App, {\n * ...\n * });\n * ```\n *\n * @param props.baseURL - Base URL for the RESTful API endpoint, e.g., https://cori-data-api.ruralinnovation.us.\n * @param props.fetchAuthSession - An optional function from the Amplify Auth package to start an authenticated session\n * @param props.getCurrentUser - An optional function from the Amplify Cognito package to fetch the current authenticated user (if any)\n * @param props.signOut - An optional function that is one of many destructured props contained in the Amplify authenticator context (returned by the useAuthenticator() hoook), used to sign out the current user.\n */\nexport default function ApiContextProvider (props: {\n children?: ReactElement | ReactElement[],\n baseURL?: string,\n fetchAuthSession?: Function,\n getCurrentUser?: Function,\n signOut?: Function\n}) {\n\n // const [ authenticated_user, setAuthenticatedUser ] = useState(null);\n // const userState = useSelector(selectUser);\n // const dispatch = useDispatch();\n\n const [ state, setState ] = useState({\n ...initState,\n setData\n });\n\n function setData(newData: any) {\n const currentState: ApiContextType = state!;\n setState({\n ...currentState,\n baseURL: (!!props.baseURL) ? props.baseURL : BASE_URL,\n data: {\n ...currentState.data,\n ...newData\n },\n setData: setData\n });\n }\n\n if (!!props.baseURL && props.baseURL.length > 0) {\n apiClient.interceptors.request.use(\n (config) => {\n config.baseURL = props.baseURL;\n console.log(\"API baseURL updated:\", config.baseURL);\n return config;\n },\n (error) => Promise.reject(error)\n );\n }\n\n useEffect(() => {\n\n setState({\n ...state,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: (!!props.baseURL) ? props.baseURL : BASE_URL,\n // setData\n });\n\n if (!!props.fetchAuthSession) {\n\n const {\n fetchAuthSession\n } = props;\n\n const session: Promise = fetchAuthSession();\n\n session\n .then((sess) => {\n\n if (!hasAuthSession) {\n\n const tokens = sess.tokens!;\n\n console.log(\"API tokens:\", tokens);\n\n if (!!tokens && tokens.hasOwnProperty(\"idToken\")) {\n\n hasAuthSession = true;\n\n console.log(\"API Session is authenticated:\", hasAuthSession);\n console.log(\"API Session config:\", sess);\n\n console.log(\"idToken:\", tokens.idToken!);\n\n apiClient.interceptors.request.use(\n (config) => {\n const accessToken = tokens.idToken!;\n if (!!accessToken) {\n config.headers.Authorization = `Bearer ${accessToken}`;\n }\n if (!!props.baseURL) {\n config.baseURL = props.baseURL;\n }\n return config;\n },\n (error) => Promise.reject(error)\n );\n\n setState({\n ...state,\n authenticated: true,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: props.baseURL || BASE_URL,\n // setData,\n token: tokens.idToken!\n });\n\n // TODO: Use autoSignOut to prompt user to refresh session on API error\n // const remoteAPIStartTime = performance.now();\n // apiClient.get(...)\n // .then(response => ...)\n // .catch(error => {\n // const remoteAPIEndTime = performance.now();\n //\n // (window as any)[\"remoteAPIExecutionTime\"] = remoteAPIEndTime - remoteAPIStartTime;\n // console.debug(`Remote API Call Execution took ${(window as any)[\"remoteAPIExecutionTime\"]} ms`);\n //\n // if (error.hasOwnProperty(\"code\")) {\n // console.log(\"Error code:\", error.code!);\n // if (error.code! === \"ERR_BAD_REQUEST\"\n // || error.code! === \"ERR_NETWORK\"\n // ) {\n // autoSignOut();\n //\n // } else if (error.code === 'ERR_NAME_NOT_RESOLVED') {\n // console.error('Invalid baseURL:', apiClient.defaults.baseURL);\n // // Handle invalid baseURL error\n // }\n // } else {\n // console.log(error.toString());\n // }\n // });\n\n if (!!props.getCurrentUser) {\n\n const { getCurrentUser } = props;\n\n const user: Promise = getCurrentUser();\n\n user.then((u) => {\n if (!hasAuthUser) {\n\n // console.log(\"Initial userState:\", userState);\n\n hasAuthUser = true;\n\n console.log(\"API User is authenticated:\", hasAuthSession);\n console.log(\"API User:\", u);\n console.log(\"API User type:\", u.constructor.name);\n\n // function updateUser (u: User) {\n // try {\n // if (!!u.userId) {\n // console.log(\"Update userId:\", u.userId);\n // dispatch(updateUserId(u.userId));\n // }\n // if (!!u.userId && !!u.username) {\n // console.log(\"Update username:\", u.username);\n // dispatch(updateUserName(u.username));\n // }\n //\n // if (!!tokens.idToken) {\n // console.log(\"Update user tokens:\", tokens);\n // dispatch(updateUserTokens(JSON.stringify(tokens)));\n // }\n //\n // } catch (e: any) {\n // console.error(e);\n // }\n\n setState({\n ...state,\n authenticated: true,\n authenticated_user: u,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: props.baseURL || BASE_URL,\n // setData,\n token: tokens.idToken!\n });\n\n // setAuthenticatedUser(u);\n // }\n\n // updateUser(u);\n }\n });\n }\n }\n }\n });\n }\n\n }, []);\n\n return (<>\n \n {/**/}\n {props.children}\n {/**/}\n \n );\n}\n"],"names":["React"],"mappings":";;;;;;;;;AAqBA,MAAM,QAAQ,GAAG,2CAA2C,CAAC;AA8C7D,MAAM,SAAS,GAAkB,KAAK,CAAC,MAAM,CAAC;AAC1C,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,OAAO,EAAE;AACL,QAAA,cAAc,EAAE,kBAAkB;AACrC,KAAA;AACJ,CAAA,CAAC,CAAC;AAEH,MAAM,OAAO,GAAQ,EAAE,CAAC;AAExB,MAAM,SAAS,GAAmB;AAC9B,IAAA,SAAS,EAAE,SAAS;AACpB,IAAA,aAAa,EAAE,KAAK;AACpB,IAAA,kBAAkB,EAAE,IAAI;AACxB,IAAA,WAAW,EAAE,IAAI;AACjB,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,KAAK,EAAE,IAAI;AACX,IAAA,IAAI,EAAE;AACF,QAAA,GAAG,EAAE,MAAM,OAAO;AAClB,QAAA,GAAG,EAAE,CAAC,OAAY,KAAI;AAClB,YAAA,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;AACrB,gBAAA,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;AAC3B,oBAAA,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;iBACxB;aACJ;SACJ;AACJ,KAAA;AACD,IAAA,OAAO,EAAE,CAAC,OAAY,KAAI;AACtB,QAAA,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;AACrB,YAAA,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;AAC3B,gBAAA,OAAO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QAAQ,CAAC,QAAQ,CAAC;yCAChH,GAAG,IAAI,EACR,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,QAAQ;;AAElC,wCAAA,KAAK,EAAE,MAAM,CAAC,OAAQ,IACxB,CAAC;;;;iCAMV;AACL,6BAAC,CAAC,CAAC;yBACN;qBACJ;iBACJ;AACL,aAAC,CAAC,CAAC;SACV;KAEJ,EAAE,EAAE,CAAC,CAAC;AAEP,IAAA,QAAQA,cAAA,CAAA,aAAA,CAAAA,cAAA,CAAA,QAAA,EAAA,IAAA;AACJ,QAAAA,cAAA,CAAA,aAAA,CAAC,UAAU,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAExB,EAAA,KAAK,CAAC,QAAQ,CAED,CACvB,EAAE;AACT;;;;"} \ No newline at end of file +{"version":3,"file":"ApiContextProvider.js","sources":["../../../../lib/@cori-risi/contexts/ApiContextProvider.tsx"],"sourcesContent":["import React, {\n createContext,\n ReactElement,\n // useContext,\n useEffect,\n useState\n} from \"react\";\nimport axios, { AxiosInstance } from 'axios';\nimport { AuthTokens, JWT } from \"@aws-amplify/auth\";\n// import { useDispatch, useSelector } from \"react-redux\";\n// import {\n// updateUserId,\n// updateUserName,\n// updateUserTokens,\n// selectUser\n// } from \"../features\";\n// import { User } from '../models';\n\nimport \"./styles/ApiContextProvider.css\";\nimport { User } from \"../models\";\n\nconst BASE_URL = \"https://cori-data-api.ruralinnovation.us/\"; // `${import.meta.env.VITE_CORI_DATA_API}`;\n// TODO: From now on must pass dev/prod API url in as param to ApiContextProvider because:\n// cori.data.api/lib/@cori-risi/cotexts/ApiContextProvider.tsx:22\n// const BASE_URL = `${import.meta.env.VITE_CORI_DATA_API}`;\n// ^^^^\n// SyntaxError: Cannot use 'import.meta' outside a module\n//\n\ntype AWSCredentials = {\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n expiration?: Date;\n};\n\ntype AuthSession = {\n tokens?: AuthTokens;\n credentials?: AWSCredentials;\n identityId?: string;\n userSub?: string;\n};\n\n/**\n * This is the interface/type of the [`ApiContext`](../variables/ApiContext.md).\n *\n * @property apiClient Axios client for RESTful services\n * @property authenticated `true` if the ApiContextProvider has established an authenticated session\n * @property authenticated_user the current user state if the ApiContextProvider has established an authenticated session\n * @property autoSignOut a function that can be called to terminate the current session (if using authentication)\n * @property baseURL Base URL for RESTful service\n * @property token id token retrieved from Cognito which is used in requests made by the `apiClient` (if using authentication)\n * @property data read-only data store\n * @property setData setter to update data store\n * @interface\n */\nexport interface ApiContextType {\n apiClient: AxiosInstance;\n authenticated: boolean;\n authenticated_user: User | null;\n autoSignOut: (() => void) | null;\n baseURL: string;\n token: JWT | null;\n data: any;\n setData: ((newData: any) => void);\n}\n\nconst apiClient: AxiosInstance = axios.create({\n baseURL: BASE_URL,\n headers: {\n 'Content-Type': 'application/json'\n },\n});\n\nconst apiData: any = {};\n\nconst initState: ApiContextType = {\n apiClient: apiClient,\n authenticated: false,\n authenticated_user: null,\n autoSignOut: null,\n baseURL: BASE_URL,\n token: null,\n data: {\n get: () => apiData,\n set: (newData: any) => {\n for (const d in newData) {\n if (newData.hasOwnProperty[d]) {\n apiData[d] = newData;\n }\n }\n }\n },\n setData: (newData: any) => {\n for (const d in newData) {\n if (newData.hasOwnProperty[d]) {\n apiData[d] = newData;\n }\n }\n }\n};\n\n/**\n * This is the data/api context for a React app that uses network requests to fetch data from either a RESTful\n * service backend or a GraphQL service backend (both are available in the\n * [CORI Data API](https://cori-data-api.ruralinnovation.us/){target=_blank}). See\n * [`ApiContextType`](../interfaces/ApiContextType.md) for a list of props offered by this context.\n *\n * Note that GraphQL queries require a special client that can be instantiated by an additional context provider component\n * (i.e. [ApolloGraphQLProvider](https://github.com/ruralinnovation/amplify-bcat/tree/main/src/%40cori-risi/bcat/contexts){target=_blank}).\n *\n */\nexport const ApiContext = createContext(initState);\n\nlet hasAuthSession = false;\nlet hasAuthUser = false;\nlet hasAuthClient = false;\n\n/**\n * This component provides the API/data service context ([`ApiContext`](../variables/ApiContext.md)) to a React\n * application. The following example assumes that the `App` component has been configured by the\n * [`AmplifyContextProvider`](../functions/AmplifyContextProvider.md) to allow for authentication\n * with AWS Cognito, but this provider can also be used to setup an ApiContext with no authentication (by only using\n * the `baseURL` param/prop and disregarding the other props):\n *\n * ```ts\n * import {\n * withAuthenticator,\n * useAuthenticator,\n * UseAuthenticator, useTheme, Heading\n * } from '@aws-amplify/ui-react';\n * import { fetchAuthSession } from \"@aws-amplify/auth\";\n * import { getCurrentUser } from \"@aws-amplify/auth/cognito\";\n * import { AmplifyContext, ApiContextProvider } from \"@cori-risi/cori.data.api\";\n *\n * // ...\n *\n * const App = () => {\n *\n * const amplifyContext = useContext(AmplifyContext);\n * const authenticator: UseAuthenticator = useAuthenticator();\n *\n * // ...\n *\n * return (\n * \n * \n * \n * );\n * }\n *\n * export default withAuthenticator(App, {\n * ...\n * });\n * ```\n *\n * @param props.baseURL - Base URL for the RESTful API endpoint, e.g., https://cori-data-api.ruralinnovation.us.\n * @param props.fetchAuthSession - An optional function from the Amplify Auth package to start an authenticated session\n * @param props.getCurrentUser - An optional function from the Amplify Cognito package to fetch the current authenticated user (if any)\n * @param props.signOut - An optional function that is one of many destructured props contained in the Amplify authenticator context (returned by the useAuthenticator() hoook), used to sign out the current user.\n */\nexport default function ApiContextProvider (props: {\n children?: ReactElement | ReactElement[],\n baseURL?: string,\n fetchAuthSession?: Function,\n getCurrentUser?: Function,\n signOut?: Function\n}) {\n\n // const [ authenticated_user, setAuthenticatedUser ] = useState(null);\n // const userState = useSelector(selectUser);\n // const dispatch = useDispatch();\n\n const [ state, setState ] = useState({\n ...initState,\n baseURL: (!!props.baseURL) ? props.baseURL : BASE_URL,\n setData\n });\n\n function setData(newData: any) {\n const currentState: ApiContextType = state!;\n setState({\n ...currentState,\n data: {\n ...currentState.data,\n ...newData\n },\n setData: setData\n });\n }\n\n if (!!props.baseURL && props.baseURL.length > 0) {\n apiClient.interceptors.request.use(\n (config) => {\n config.baseURL = props.baseURL;\n console.log(\"API baseURL updated:\", config.baseURL);\n return config;\n },\n (error) => Promise.reject(error)\n );\n }\n\n useEffect(() => {\n\n setState({\n ...state,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: (!!props.baseURL) ? props.baseURL : BASE_URL,\n // setData\n });\n\n if (!!props.fetchAuthSession) {\n\n const {\n fetchAuthSession\n } = props;\n\n const session: Promise = fetchAuthSession();\n\n session\n .then((sess) => {\n\n if (!hasAuthSession) {\n\n const tokens = sess.tokens!;\n\n console.log(\"API tokens:\", tokens);\n\n if (!!tokens && tokens.hasOwnProperty(\"idToken\")) {\n\n hasAuthSession = true;\n\n console.log(\"API Session is authenticated:\", hasAuthSession);\n console.log(\"API Session config:\", sess);\n\n console.log(\"idToken:\", tokens.idToken!);\n\n apiClient.interceptors.request.use(\n (config) => {\n const accessToken = tokens.idToken!;\n if (!!accessToken) {\n config.headers.Authorization = `Bearer ${accessToken}`;\n }\n if (!!props.baseURL) {\n config.baseURL = props.baseURL;\n }\n return config;\n },\n (error) => Promise.reject(error)\n );\n\n setState({\n ...state,\n authenticated: true,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: props.baseURL || BASE_URL,\n // setData,\n token: tokens.idToken!\n });\n\n // TODO: Use autoSignOut to prompt user to refresh session on API error\n // const remoteAPIStartTime = performance.now();\n // apiClient.get(...)\n // .then(response => ...)\n // .catch(error => {\n // const remoteAPIEndTime = performance.now();\n //\n // (window as any)[\"remoteAPIExecutionTime\"] = remoteAPIEndTime - remoteAPIStartTime;\n // console.debug(`Remote API Call Execution took ${(window as any)[\"remoteAPIExecutionTime\"]} ms`);\n //\n // if (error.hasOwnProperty(\"code\")) {\n // console.log(\"Error code:\", error.code!);\n // if (error.code! === \"ERR_BAD_REQUEST\"\n // || error.code! === \"ERR_NETWORK\"\n // ) {\n // autoSignOut();\n //\n // } else if (error.code === 'ERR_NAME_NOT_RESOLVED') {\n // console.error('Invalid baseURL:', apiClient.defaults.baseURL);\n // // Handle invalid baseURL error\n // }\n // } else {\n // console.log(error.toString());\n // }\n // });\n\n if (!!props.getCurrentUser) {\n\n const { getCurrentUser } = props;\n\n const user: Promise = getCurrentUser();\n\n user.then((u) => {\n if (!hasAuthUser) {\n\n // console.log(\"Initial userState:\", userState);\n\n hasAuthUser = true;\n\n console.log(\"API User is authenticated:\", hasAuthSession);\n console.log(\"API User:\", u);\n console.log(\"API User type:\", u.constructor.name);\n\n // function updateUser (u: User) {\n // try {\n // if (!!u.userId) {\n // console.log(\"Update userId:\", u.userId);\n // dispatch(updateUserId(u.userId));\n // }\n // if (!!u.userId && !!u.username) {\n // console.log(\"Update username:\", u.username);\n // dispatch(updateUserName(u.username));\n // }\n //\n // if (!!tokens.idToken) {\n // console.log(\"Update user tokens:\", tokens);\n // dispatch(updateUserTokens(JSON.stringify(tokens)));\n // }\n //\n // } catch (e: any) {\n // console.error(e);\n // }\n\n setState({\n ...state,\n authenticated: true,\n authenticated_user: u,\n autoSignOut: (!!props.signOut && typeof props.signOut === \"function\") ? () => {\n const { signOut } = props;\n (signOut!)();\n window.alert(\"Please refresh this session by clicking the browser's reload button!\");\n (window as any).location = window.location.protocol + \"//\" + window.location.host + window.location.pathname;\n } : null,\n baseURL: props.baseURL || BASE_URL,\n // setData,\n token: tokens.idToken!\n });\n\n // setAuthenticatedUser(u);\n // }\n\n // updateUser(u);\n }\n });\n }\n }\n }\n });\n }\n\n }, []);\n\n return (<>\n \n {/**/}\n {props.children}\n {/**/}\n \n );\n}\n"],"names":["React"],"mappings":";;;;;;;;;AAqBA,MAAM,QAAQ,GAAG,2C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J,QAAAA,cAAA,CAAA,aAAA,CAAC,UAAU,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAExB,EAAA,KAAK,CAAC,QAAQ,CAED,CACvB,EAAE;AACT;;;;"} \ No newline at end of file diff --git a/lib/@cori-risi/contexts/ApiContextProvider.tsx b/lib/@cori-risi/contexts/ApiContextProvider.tsx index c791fd6c..3bca86fe 100644 --- a/lib/@cori-risi/contexts/ApiContextProvider.tsx +++ b/lib/@cori-risi/contexts/ApiContextProvider.tsx @@ -176,6 +176,7 @@ export default function ApiContextProvider (props: { const [ state, setState ] = useState({ ...initState, + baseURL: (!!props.baseURL) ? props.baseURL : BASE_URL, setData }); @@ -183,7 +184,6 @@ export default function ApiContextProvider (props: { const currentState: ApiContextType = state!; setState({ ...currentState, - baseURL: (!!props.baseURL) ? props.baseURL : BASE_URL, data: { ...currentState.data, ...newData