Skip to content

Commit

Permalink
⚡ Fixing node auth options logic for multiple auth fields
Browse files Browse the repository at this point in the history
  • Loading branch information
MiloradFilipovic committed Dec 30, 2022
1 parent 64c8773 commit d994904
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions packages/editor-ui/src/utils/nodeTypesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,22 @@ export const getNodeAuthOptions = (
if (nodeType) {
let options: NodeAuthenticationOption[] = [];
const authProp = getMainAuthField(nodeType);
if (authProp && authProp.options) {
options = options.concat(
authProp.options.map((option) => ({
name: option.name,
value: option.value,
// Also add in the display options so we can hide/show the option if necessary
displayOptions: authProp.displayOptions,
})) || [],
);
}
// Some nodes have multiple auth fields with same name but different display options so need
// take them all into account
const authProps = getNodeAuthFields(nodeType).filter((prop) => prop.name === authProp?.name);

authProps.forEach((field) => {
if (field.options) {
options = options.concat(
field.options.map((option) => ({
name: option.name,
value: option.value,
// Also add in the display options so we can hide/show the option if necessary
displayOptions: field.displayOptions,
})) || [],
);
}
});
return options;
}
return [];
Expand Down Expand Up @@ -403,9 +409,13 @@ export const getNodeAuthFields = (nodeType: INodeTypeDescription | null): INodeP
nodeType.credentials.forEach((cred) => {
if (cred.displayOptions && cred.displayOptions.show) {
Object.keys(cred.displayOptions.show).forEach((option) => {
const nodeFieldForName = nodeType.properties.find((prop) => prop.name === option);
if (nodeFieldForName && !authFields.find((f) => f.name === option)) {
authFields.push(nodeFieldForName);
const nodeFieldsForName = nodeType.properties.filter((prop) => prop.name === option);
if (nodeFieldsForName) {
nodeFieldsForName.forEach((nodeField) => {
if (!authFields.includes(nodeField)) {
authFields.push(nodeField);
}
});
}
});
}
Expand Down

0 comments on commit d994904

Please sign in to comment.