Skip to content

Commit

Permalink
fix: Fix edge case in log in (no-changelog) (#10610)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi authored Aug 30, 2024
1 parent 1c5164c commit 1b409b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { strict as assert } from 'node:assert';
import type { AxiosRequestConfig } from 'axios';
import { N8nApiClient } from './n8nApiClient';

Expand All @@ -16,15 +15,33 @@ export class AuthenticatedN8nApiClient extends N8nApiClient {
email: string;
password: string;
},
) {
): Promise<AuthenticatedN8nApiClient> {
const response = await apiClient.restApiRequest('/login', {
method: 'POST',
data: loginDetails,
});

if (response.data === 'n8n is starting up. Please wait') {
await apiClient.delay(1000);
return await this.createUsingUsernameAndPassword(apiClient, loginDetails);
}

const cookieHeader = response.headers['set-cookie'];
const authCookie = Array.isArray(cookieHeader) ? cookieHeader.join('; ') : cookieHeader;
assert(authCookie);
if (!authCookie) {
throw new Error(
'Did not receive authentication cookie even tho login succeeded: ' +
JSON.stringify(
{
status: response.status,
headers: response.headers,
data: response.data,
},
null,
2,
),
);
}

return new AuthenticatedN8nApiClient(apiClient.apiBaseUrl, authCookie);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/@n8n/benchmark/src/n8nApiClient/n8nApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export class N8nApiClient {
}
}

protected getRestEndpointUrl(endpoint: string) {
return `${this.apiBaseUrl}/rest${endpoint}`;
async delay(ms: number): Promise<void> {
return await new Promise((resolve) => setTimeout(resolve, ms));
}

private async delay(ms: number): Promise<void> {
return await new Promise((resolve) => setTimeout(resolve, ms));
protected getRestEndpointUrl(endpoint: string) {
return `${this.apiBaseUrl}/rest${endpoint}`;
}
}

0 comments on commit 1b409b4

Please sign in to comment.