mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
fix: Fix edge case in log in (no-changelog) (#10610)
This commit is contained in:
parent
1c5164c786
commit
1b409b4e3e
|
@ -1,4 +1,3 @@
|
|||
import { strict as assert } from 'node:assert';
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
import { N8nApiClient } from './n8nApiClient';
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -75,11 +75,11 @@ export class N8nApiClient {
|
|||
}
|
||||
}
|
||||
|
||||
async delay(ms: number): Promise<void> {
|
||||
return await new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
protected getRestEndpointUrl(endpoint: string) {
|
||||
return `${this.apiBaseUrl}/rest${endpoint}`;
|
||||
}
|
||||
|
||||
private async delay(ms: number): Promise<void> {
|
||||
return await new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue