Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix edge case in log in (no-changelog) #10610

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`;
}
}
Loading