mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(Strapi Node): Strapi credentials notice (#6289)
This commit is contained in:
@@ -10,11 +10,17 @@ import type {
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export const removeTrailingSlash = (url: string) => {
|
||||
if (url.endsWith('/')) {
|
||||
return url.slice(0, -1);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
export async function strapiApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions | IWebhookFunctions,
|
||||
method: string,
|
||||
resource: string,
|
||||
|
||||
body: IDataObject = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
@@ -22,16 +28,15 @@ export async function strapiApiRequest(
|
||||
) {
|
||||
const credentials = await this.getCredentials('strapiApi');
|
||||
|
||||
const url = removeTrailingSlash(credentials.url as string);
|
||||
|
||||
try {
|
||||
const options: OptionsWithUri = {
|
||||
headers: {},
|
||||
method,
|
||||
body,
|
||||
qs,
|
||||
uri:
|
||||
uri || credentials.apiVersion === 'v4'
|
||||
? `${credentials.url}/api${resource}`
|
||||
: `${credentials.url}${resource}`,
|
||||
uri: uri || credentials.apiVersion === 'v4' ? `${url}/api${resource}` : `${url}${resource}`,
|
||||
json: true,
|
||||
qsStringifyOptions: {
|
||||
arrayFormat: 'indice',
|
||||
@@ -54,6 +59,9 @@ export async function getToken(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions | IWebhookFunctions,
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('strapiApi');
|
||||
|
||||
const url = removeTrailingSlash(credentials.url as string);
|
||||
|
||||
let options = {} as OptionsWithUri;
|
||||
options = {
|
||||
headers: {
|
||||
@@ -64,10 +72,7 @@ export async function getToken(
|
||||
identifier: credentials.email,
|
||||
password: credentials.password,
|
||||
},
|
||||
uri:
|
||||
credentials.apiVersion === 'v4'
|
||||
? `${credentials.url}/api/auth/local`
|
||||
: `${credentials.url}/auth/local`,
|
||||
uri: credentials.apiVersion === 'v4' ? `${url}/api/auth/local` : `${url}/auth/local`,
|
||||
json: true,
|
||||
};
|
||||
return this.helpers.request(options);
|
||||
|
||||
Reference in New Issue
Block a user