Skip to content

Commit 9588dbc

Browse files
committed
Open the connection modal on a key method, not OAuth
OAuth needs a registered app (or a DCR round-trip) before Connect does anything, so an integration declaring both greeted most users with "Register app" — a dead end — while the working method sat one tab over. The modal now opens on the first non-OAuth method; OAuth stays one click away, and a handoff-specified template still wins.
1 parent 6e3cd06 commit 9588dbc

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

packages/react/src/components/add-account-modal.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,14 @@ export const connectionExistsMessage = (label: string): string =>
627627
* explicit choice. Personal: a connection is most often a personal credential. */
628628
export const DEFAULT_CONNECTION_OWNER: Owner = "user";
629629

630+
/** The method the modal opens on. OAuth needs a registered app (or a DCR
631+
* round-trip) before "Connect" does anything; a key is one paste. When an
632+
* integration declares both, starting on OAuth greets most users with
633+
* "Register app" — a dead end — while the working method sits one tab over.
634+
* Prefer the first non-OAuth method; OAuth stays one click away. */
635+
export const preferredMethodId = (methods: readonly AuthMethod[]): string =>
636+
(methods.find((method) => method.kind !== "oauth") ?? methods[0])?.id ?? "";
637+
630638
const authMethodKey = (method: AuthMethod): string =>
631639
method.source === "custom" ? `custom:${String(method.template)}` : `declared:${method.id}`;
632640

@@ -1425,7 +1433,7 @@ function AddAccountModalView(props: AddAccountModalProps) {
14251433
);
14261434
const [addingMethod, setAddingMethod] = useState(false);
14271435

1428-
const [methodId, setMethodId] = useState<string>(methods[0]?.id ?? "");
1436+
const [methodId, setMethodId] = useState<string>(preferredMethodId(methods));
14291437
// One value per distinct credential input (`variable → pasted value`). A
14301438
// single-secret method has just `{ token }`; a method with two distinct inputs
14311439
// (e.g. Datadog's two keys) collects one value per variable.
@@ -1613,7 +1621,7 @@ function AddAccountModalView(props: AddAccountModalProps) {
16131621
m.id === initialState.template || String(m.template) === initialState.template,
16141622
)
16151623
: undefined;
1616-
setMethodId(initialMethod?.id ?? allMethods[0]!.id);
1624+
setMethodId(initialMethod?.id ?? preferredMethodId(allMethods));
16171625
}, [allMethods, initialState?.template, methodId]);
16181626

16191627
// Non-secret prefill carried by an `oauth.clients.createHandoff` deep link.

0 commit comments

Comments
 (0)