Skip to content

Commit 1b409b4

Browse files
authored
fix: Fix edge case in log in (no-changelog) (#10610)
1 parent 1c5164c commit 1b409b4

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

packages/@n8n/benchmark/src/n8nApiClient/authenticatedN8nApiClient.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { strict as assert } from 'node:assert';
21
import type { AxiosRequestConfig } from 'axios';
32
import { N8nApiClient } from './n8nApiClient';
43

@@ -16,15 +15,33 @@ export class AuthenticatedN8nApiClient extends N8nApiClient {
1615
email: string;
1716
password: string;
1817
},
19-
) {
18+
): Promise<AuthenticatedN8nApiClient> {
2019
const response = await apiClient.restApiRequest('/login', {
2120
method: 'POST',
2221
data: loginDetails,
2322
});
2423

24+
if (response.data === 'n8n is starting up. Please wait') {
25+
await apiClient.delay(1000);
26+
return await this.createUsingUsernameAndPassword(apiClient, loginDetails);
27+
}
28+
2529
const cookieHeader = response.headers['set-cookie'];
2630
const authCookie = Array.isArray(cookieHeader) ? cookieHeader.join('; ') : cookieHeader;
27-
assert(authCookie);
31+
if (!authCookie) {
32+
throw new Error(
33+
'Did not receive authentication cookie even tho login succeeded: ' +
34+
JSON.stringify(
35+
{
36+
status: response.status,
37+
headers: response.headers,
38+
data: response.data,
39+
},
40+
null,
41+
2,
42+
),
43+
);
44+
}
2845

2946
return new AuthenticatedN8nApiClient(apiClient.apiBaseUrl, authCookie);
3047
}

packages/@n8n/benchmark/src/n8nApiClient/n8nApiClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ export class N8nApiClient {
7575
}
7676
}
7777

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

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

0 commit comments

Comments
 (0)