Skip to content

Commit 6e94249

Browse files
teallarsonTim Roes
andauthored
🪟 🐛 New OAuth connectors should never say "re-authenticate" (#18487)
* 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 <[email protected]> Co-authored-by: Tim Roes <[email protected]>
1 parent 51ac4b5 commit 6e94249

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

airbyte-webapp/src/views/Connector/ServiceForm/components/Sections/auth/useOauthFlowAdapter.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useMemo, useState } from "react";
88
import { ConnectorDefinitionSpecification } from "core/domain/connector";
99
import { AuthSpecification } from "core/request/AirbyteClient";
1010
import { useRunOauthFlow } from "hooks/services/useConnectorAuth";
11+
import { useAuthentication } from "views/Connector/ServiceForm/useAuthentication";
1112

1213
import { useServiceForm } from "../../../serviceFormContext";
1314
import { ServiceFormValues } from "../../../types";
@@ -51,13 +52,12 @@ function useFormikOauthAdapter(connector: ConnectorDefinitionSpecification): {
5152

5253
const { run, loading, done } = useRunOauthFlow(connector, onDone);
5354
const preparedValues = useMemo(() => getValues<Credentials>(values), [getValues, values]);
54-
const connectionObjectEmpty = preparedValues?.connectionConfiguration?.credentials
55-
? Object.keys(preparedValues.connectionConfiguration?.credentials).length <= 1
56-
: true;
55+
56+
const { hasAuthFieldValues } = useAuthentication();
5757

5858
return {
5959
loading,
60-
done: done || !connectionObjectEmpty,
60+
done: done || hasAuthFieldValues,
6161
hasRun,
6262
run: async () => {
6363
const oauthInputProperties =

airbyte-webapp/src/views/Connector/ServiceForm/useAuthentication.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ interface AuthenticationHook {
122122
* the passed in field, and false otherwise.
123123
*/
124124
shouldShowAuthButton: (fieldPath: string) => boolean;
125+
/**
126+
* This will return true if any of the hidden auth fields have values. This determines
127+
* whether we will render "authenticate" or "re-authenticate" on the OAuth button text
128+
*/
129+
hasAuthFieldValues: boolean;
125130
}
126131

127132
export const useAuthentication = (): AuthenticationHook => {
@@ -202,9 +207,14 @@ export const useAuthentication = (): AuthenticationHook => {
202207
[advancedAuth, isAuthButtonVisible, legacyOauthSpec]
203208
);
204209

210+
const hasAuthFieldValues: boolean = useMemo(() => {
211+
return implicitAuthFieldPaths.some((path) => getIn(values, path) !== undefined);
212+
}, [implicitAuthFieldPaths, values]);
213+
205214
return {
206215
isHiddenAuthField,
207216
hiddenAuthFieldErrors,
208217
shouldShowAuthButton,
218+
hasAuthFieldValues,
209219
};
210220
};

0 commit comments

Comments
 (0)