Use correct credential name

This commit is contained in:
Elias Meire 2024-09-26 12:18:14 +02:00
parent efc809592a
commit 768cecedc5
No known key found for this signature in database
2 changed files with 7 additions and 9 deletions

View file

@ -2005,7 +2005,7 @@ export async function getCredentials<T extends object = ICredentialDataDecrypted
connectionInputData?: INodeExecutionData[],
itemIndex?: number,
): Promise<T> {
const type = typeof credType === 'string' ? credType : credType.name;
const type = typeof credType === 'string' ? credType : new credType().name;
// Get the NodeType as it has the information if the credentials are required
const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
if (nodeType === undefined) {

View file

@ -9,7 +9,9 @@ import type {
JsonObject,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import type { StrapiApiCredential } from '@credentials/StrapiApi.credentials';
import { StrapiApi } from '@credentials/StrapiApi.credentials';
import { StrapiTokenApi } from '@credentials/StrapiTokenApi.credentials';
export const removeTrailingSlash = (url: string) => {
if (url.endsWith('/')) {
@ -28,13 +30,9 @@ export async function strapiApiRequest(
headers: IDataObject = {},
) {
const authenticationMethod = this.getNodeParameter('authentication', 0);
let credentials: Pick<StrapiApiCredential, 'apiVersion' | 'url'>;
if (authenticationMethod === 'password') {
credentials = await this.getCredentials('strapiApi');
} else {
credentials = await this.getCredentials('strapiTokenApi');
}
const credentials = await this.getCredentials(
authenticationMethod === 'password' ? StrapiApi : StrapiTokenApi,
);
const url = removeTrailingSlash(credentials.url);