refactor: simplify http auth

This commit is contained in:
simon
2021-01-23 22:33:06 +01:00
parent 279541a669
commit 652ae86a8a
2 changed files with 60 additions and 27 deletions

View File

@@ -13,33 +13,25 @@ export class HTTPAuth implements IAuthentication {
}
async authenticate(username: string, password: string) {
let success = false;
try {
await axios
.post(
this.url,
{
username,
password,
},
{
validateStatus(status) {
return status >= 200 && status < 500;
},
}
)
.then((res) => {
console.log(`Code: ${res.status}`);
if (res.status === 200) {
success = true;
console.log('Return code 200, HTTP authentication successful');
} else {
console.log('HTTP authentication failed');
}
});
} catch (err) {
console.error('HTTP response error');
const result = await axios.post(
this.url,
{
username,
password,
},
{
validateStatus(status) {
return status >= 200 && status < 500;
},
}
);
if (result.status === 200) {
return true;
}
return success;
console.log(`HTTP authentication failed, response code: ${result.status}`);
return false;
}
}