From d06197d879707c6a9826ae192682262c4f6c02ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milorad=20FIlipovi=C4=87?= Date: Thu, 10 Nov 2022 12:51:50 +0100 Subject: [PATCH] fix(editor): Fix for oauth authorization (#4572) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 Fixing credentials response type check that prevented oauth authorization --- .../CredentialEdit/CredentialEdit.vue | 1 - .../components/CredentialEdit/OauthButton.vue | 1 - .../src/components/NodeCredentials.vue | 30 +++++++++++-------- packages/editor-ui/src/typeGuards.ts | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/editor-ui/src/components/CredentialEdit/CredentialEdit.vue b/packages/editor-ui/src/components/CredentialEdit/CredentialEdit.vue index caca64a4354a3..07aea62ae6574 100644 --- a/packages/editor-ui/src/components/CredentialEdit/CredentialEdit.vue +++ b/packages/editor-ui/src/components/CredentialEdit/CredentialEdit.vue @@ -118,7 +118,6 @@ import { ICredentialsDecrypted, ICredentialType, INode, - INodeCredentialTestResult, INodeParameters, INodeProperties, INodeTypeDescription, diff --git a/packages/editor-ui/src/components/CredentialEdit/OauthButton.vue b/packages/editor-ui/src/components/CredentialEdit/OauthButton.vue index e64137caf6e15..b032ede2e1126 100644 --- a/packages/editor-ui/src/components/CredentialEdit/OauthButton.vue +++ b/packages/editor-ui/src/components/CredentialEdit/OauthButton.vue @@ -20,7 +20,6 @@ import { useRootStore } from '@/stores/n8nRootStore'; import { mapStores } from 'pinia'; import Vue from 'vue'; -import mixins from 'vue-typed-mixins'; export default Vue.extend({ props: { diff --git a/packages/editor-ui/src/components/NodeCredentials.vue b/packages/editor-ui/src/components/NodeCredentials.vue index 52111370010eb..ef4d9bc3c52be 100644 --- a/packages/editor-ui/src/components/NodeCredentials.vue +++ b/packages/editor-ui/src/components/NodeCredentials.vue @@ -198,19 +198,23 @@ export default mixins( this.credentialsStore.$subscribe((mutation, state) => { // This data pro stores credential type that the component is currently interested in const credentialType = this.subscribedToCredentialType; - const credentialsOfType = this.credentialsStore.allCredentialsByType[credentialType].sort((a, b) => (a.id < b.id ? -1 : 1)); - if (credentialsOfType.length > 0) { - // If nothing has been selected previously, select the first one (newly added) - if (!this.selected[credentialType]) { - this.onCredentialSelected(credentialType, credentialsOfType[0].id); - } else { - // Else, check id currently selected cred has been updated - const newSelected = credentialsOfType.find(cred => cred.id === this.selected[credentialType].id); - // If it has changed, select it - if (newSelected && newSelected.name !== this.selected[credentialType].name) { - this.onCredentialSelected(credentialType, newSelected.id); - } else { // Else select the last cred with that type since selected has been deleted or a new one has been added - this.onCredentialSelected(credentialType, credentialsOfType[credentialsOfType.length - 1].id); + let credentialsOfType = this.credentialsStore.allCredentialsByType[credentialType]; + + if (credentialsOfType) { + credentialsOfType = credentialsOfType.sort((a, b) => (a.id < b.id ? -1 : 1)); + if (credentialsOfType.length > 0) { + // If nothing has been selected previously, select the first one (newly added) + if (!this.selected[credentialType]) { + this.onCredentialSelected(credentialType, credentialsOfType[0].id); + } else { + // Else, check id currently selected cred has been updated + const newSelected = credentialsOfType.find(cred => cred.id === this.selected[credentialType].id); + // If it has changed, select it + if (newSelected && newSelected.name !== this.selected[credentialType].name) { + this.onCredentialSelected(credentialType, newSelected.id); + } else { // Else select the last cred with that type since selected has been deleted or a new one has been added + this.onCredentialSelected(credentialType, credentialsOfType[credentialsOfType.length - 1].id); + } } } } diff --git a/packages/editor-ui/src/typeGuards.ts b/packages/editor-ui/src/typeGuards.ts index 43ec2a0417572..f76537b33c0b8 100644 --- a/packages/editor-ui/src/typeGuards.ts +++ b/packages/editor-ui/src/typeGuards.ts @@ -10,5 +10,5 @@ export function isNotNull(value: T | null): value is T { } export function isValidCredentialResponse(value: unknown): value is ICredentialsResponse { - return typeof value === 'object' && value !== null && 'id' in value && 'createdAt' in value && 'updatedAt' in value; + return typeof value === 'object' && value !== null && 'id' in value; }