Hi everyone,
I am using ionic 4, for login I am using above code. This code was working in real test android devices which have apk already but today code is triggered onerror with 0 error status. I tried in different android device, everything is okey. Can you help me?
in real
login() {
this.isSubmitted = true;
if (!this.loginModel.isValid()) return;
var xhr = new XMLHttpRequest();
xhr.open("POST", server_url2 + "/oauth/token", true);
xhr.withCredentials = false;
xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
var requestParams = "grant_type=password&username=" + encodeURIComponent(this.loginModel.username) + "&password=" + encodeURIComponent(this.loginModel.password);
this.loadingService.showLoader(this.loading);
xhr.send(requestParams);
xhr.onload = () => {
if (xhr.status == 200) {
let response = JSON.parse(xhr.responseText);
this.storage.set("token", response['access_token']);
//localStorage.setItem("token", response['access_token']);
if (this.loginModel.username === "halim.terzioglu" || this.loginModel.username === "gorkem.azder"
|| this.loginModel.username === "ngssrgunaydin") {
this.isAdmin = true;
localStorage.setItem("adminUser", this.loginModel.username);
this.appPages.push({
header: 'Test News',
url: '/news-test',
icon: '../theme/icons/menu/ic-map-off.svg',
selectedIcon: '../theme/icons/menu/ic-map-active.svg',
expanded: false,
});
}
this.isLogged = true;
this.show = true;
this.loadingService.hideLoader();
this.router.navigateByUrl("/home");
}
else {
//localStorage.removeItem('token');
this.storage.remove("token");
localStorage.removeItem('adminUser');
this.loadingService.hideLoader();
this.alertService.showAlert("Something went wrong", "Username or password is incorrect.");
}
};
xhr.onerror = () => {
this.loadingService.hideLoader();
this.alertService.showAlert('Please check your connection!', '');
}
return;
}
for whatever reason…