From 6e94249577c0b2e48377400908db3cbc43564c80 Mon Sep 17 00:00:00 2001 From: Teal Larson Date: Fri, 4 Nov 2022 12:22:46 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=9F=20=F0=9F=90=9B=20New=20OAuth=20con?= =?UTF-8?q?nectors=20should=20never=20say=20"re-authenticate"=20(#18487)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * look for empty credential values, not empty credential keys * use a more generalizable solution, move it to the service * cleanup * use getIn instead of get * Update airbyte-webapp/src/views/Connector/ServiceForm/useAuthentication.tsx Co-authored-by: Tim Roes Co-authored-by: Tim Roes --- .../components/Sections/auth/useOauthFlowAdapter.tsx | 8 ++++---- .../views/Connector/ServiceForm/useAuthentication.tsx | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/auth/useOauthFlowAdapter.tsx b/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/auth/useOauthFlowAdapter.tsx index 0c4ce0f4eb8db..1bd1981061c6f 100644 --- a/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/auth/useOauthFlowAdapter.tsx +++ b/airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/auth/useOauthFlowAdapter.tsx @@ -8,6 +8,7 @@ import { useMemo, useState } from "react"; import { ConnectorDefinitionSpecification } from "core/domain/connector"; import { AuthSpecification } from "core/request/AirbyteClient"; import { useRunOauthFlow } from "hooks/services/useConnectorAuth"; +import { useAuthentication } from "views/Connector/ServiceForm/useAuthentication"; import { useServiceForm } from "../../../serviceFormContext"; import { ServiceFormValues } from "../../../types"; @@ -51,13 +52,12 @@ function useFormikOauthAdapter(connector: ConnectorDefinitionSpecification): { const { run, loading, done } = useRunOauthFlow(connector, onDone); const preparedValues = useMemo(() => getValues(values), [getValues, values]); - const connectionObjectEmpty = preparedValues?.connectionConfiguration?.credentials - ? Object.keys(preparedValues.connectionConfiguration?.credentials).length <= 1 - : true; + + const { hasAuthFieldValues } = useAuthentication(); return { loading, - done: done || !connectionObjectEmpty, + done: done || hasAuthFieldValues, hasRun, run: async () => { const oauthInputProperties = diff --git a/airbyte-webapp/src/views/Connector/ServiceForm/useAuthentication.tsx b/airbyte-webapp/src/views/Connector/ServiceForm/useAuthentication.tsx index b863bc4b5eadb..07af091491cb7 100644 --- a/airbyte-webapp/src/views/Connector/ServiceForm/useAuthentication.tsx +++ b/airbyte-webapp/src/views/Connector/ServiceForm/useAuthentication.tsx @@ -122,6 +122,11 @@ interface AuthenticationHook { * the passed in field, and false otherwise. */ shouldShowAuthButton: (fieldPath: string) => boolean; + /** + * This will return true if any of the hidden auth fields have values. This determines + * whether we will render "authenticate" or "re-authenticate" on the OAuth button text + */ + hasAuthFieldValues: boolean; } export const useAuthentication = (): AuthenticationHook => { @@ -202,9 +207,14 @@ export const useAuthentication = (): AuthenticationHook => { [advancedAuth, isAuthButtonVisible, legacyOauthSpec] ); + const hasAuthFieldValues: boolean = useMemo(() => { + return implicitAuthFieldPaths.some((path) => getIn(values, path) !== undefined); + }, [implicitAuthFieldPaths, values]); + return { isHiddenAuthField, hiddenAuthFieldErrors, shouldShowAuthButton, + hasAuthFieldValues, }; };