Fix login auto-retry deadlock
This commit is contained in:
Vendored
+21
-9
@@ -406,14 +406,16 @@ class AgrarmonitorConnector {
|
||||
}));
|
||||
client.interceptors.response.use(async (response) => {
|
||||
await this.options.cookieStore.save(this.cookieJar);
|
||||
if (this.autoRetry && this.isLoginRequiredResponse(response)) {
|
||||
return this.retryAfterLogin(response.config);
|
||||
const config = response.config;
|
||||
if (this.autoRetry && !config._agrarmonitorLoginRequest && this.isLoginRequiredResponse(response)) {
|
||||
return this.retryAfterLogin(config);
|
||||
}
|
||||
return response;
|
||||
}, async (error) => {
|
||||
const response = error.response;
|
||||
if (this.autoRetry && response && this.isLoginRequiredResponse(response)) {
|
||||
return this.retryAfterLogin(error.config);
|
||||
const config = error.config;
|
||||
if (this.autoRetry && response && config && !config._agrarmonitorLoginRequest && this.isLoginRequiredResponse(response)) {
|
||||
return this.retryAfterLogin(config);
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
@@ -487,11 +489,14 @@ class AgrarmonitorConnector {
|
||||
this.logger?.warn?.('loginStrategy "auto" ist veraltet; verwende Redirect-Login');
|
||||
}
|
||||
await this.performRedirectLogin();
|
||||
if (!(await this.isSessionValid({ skipAutoRetry: true }))) {
|
||||
throw new Error('Agrarmonitor-Login durchgefuehrt, Session weiterhin ungueltig - Geraet freigeschaltet? Credentials korrekt?');
|
||||
}
|
||||
await this.options.cookieStore.save(this.cookieJar);
|
||||
this.logger?.info?.('Agrarmonitor-Login erfolgreich');
|
||||
}
|
||||
async performRedirectLogin() {
|
||||
const loginPageResponse = await this.http.get('/');
|
||||
const loginPageResponse = await this.http.get('/', this.loginRequestConfig());
|
||||
const loginPageText = typeof loginPageResponse.data === 'string' ? loginPageResponse.data : '';
|
||||
if (!this.isLoginPageText(loginPageText)) {
|
||||
return;
|
||||
@@ -504,25 +509,32 @@ class AgrarmonitorConnector {
|
||||
ssoAction: "",
|
||||
ssoReturn: "",
|
||||
};
|
||||
const response = await this.http.post('/login/api/login.php', loginData, {
|
||||
const loginPostConfig = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
_agrarmonitorLoginRequest: true,
|
||||
};
|
||||
const response = await this.http.post('/login/api/login.php', loginData, loginPostConfig);
|
||||
const responseText = typeof response.data === 'string' ? response.data : '';
|
||||
if (this.isLoginPageText(responseText)) {
|
||||
throw new Error('Agrarmonitor-Redirect-Login fehlgeschlagen');
|
||||
}
|
||||
}
|
||||
async isSessionValid() {
|
||||
async isSessionValid(options = {}) {
|
||||
try {
|
||||
const response = await this.http.get('/');
|
||||
const response = await this.http.get('/', options.skipAutoRetry ? this.loginRequestConfig() : undefined);
|
||||
return !this.isLoginRequiredResponse(response);
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
loginRequestConfig() {
|
||||
return {
|
||||
_agrarmonitorLoginRequest: true,
|
||||
};
|
||||
}
|
||||
isLoginRequiredResponse(response) {
|
||||
const responseUrl = this.getResponseUrl(response);
|
||||
const responseText = typeof response.data === 'string' ? response.data : '';
|
||||
|
||||
Reference in New Issue
Block a user