diff --git a/app/client/src/sagas/DatasourcesSagas.ts b/app/client/src/sagas/DatasourcesSagas.ts index dd582ca235..bc7e5b854d 100644 --- a/app/client/src/sagas/DatasourcesSagas.ts +++ b/app/client/src/sagas/DatasourcesSagas.ts @@ -159,6 +159,7 @@ import { getCurrentEditingEnvironmentId, getCurrentEnvironmentDetails, } from "@appsmith/selectors/environmentSelectors"; +import { waitForFetchEnvironments } from "@appsmith/sagas/EnvironmentSagas"; function* fetchDatasourcesSaga( action: ReduxAction<{ workspaceId?: string } | undefined>, @@ -646,6 +647,8 @@ function* getOAuthAccessTokenSaga( return; } try { + // wait for envs to be fetched + yield call(waitForFetchEnvironments); // Get access token for datasource const response: ApiResponse = yield OAuthApi.getAccessToken( datasourceId, diff --git a/app/client/src/utils/storage.ts b/app/client/src/utils/storage.ts index 08ba9dac7c..61c1bf2288 100644 --- a/app/client/src/utils/storage.ts +++ b/app/client/src/utils/storage.ts @@ -126,7 +126,10 @@ export const saveCurrentEnvironment = async (envId: string, appId: string) => { }; // Function to fetch the current environment and related appId from indexedDB -export const getSavedCurrentEnvironmentDetails = async () => { +export const getSavedCurrentEnvironmentDetails = async (): Promise<{ + envId: string; + appId: string; +}> => { try { return ( (await store.getItem(STORAGE_KEYS.CURRENT_ENV)) || { @@ -136,6 +139,10 @@ export const getSavedCurrentEnvironmentDetails = async () => { ); } catch (error) { log.error("An error occurred when fetching current env: ", error); + return { + envId: "", + appId: "", + }; } };