I am building an app using ionic, Drupal rest api . I get this error on implementing a web service authentification “Failed to load http://localhost/drupal-8.5.3/user/login?_format=json: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access.”
I have no idea what should I do to fix this so I hope someone here has an idea what might be causing this.
public login() {
let data = JSON.stringify({
name: this.registerCredentials.name,
pass: this.registerCredentials.password,
});
let apiloginUrl = 'http://localhost/drupal-8.5.3/user/login?_format=json';
let headers = new Headers();
headers.append('Content-Type', 'application/json');
this.http.post(apiloginUrl, data, {headers: headers})
.subscribe(data => {
localStorage.setItem('loggedinData', data['_body']);
let apiTokenUrl = 'http://localhost/drupal-8.5.3/oauth/token';
this.http.get(apiTokenUrl)
.subscribe(data => {
localStorage.setItem('loggedin_token', data['_body']);
}, error => {
console.log(error);// Error getting the data
});
this.navCtrl.setRoot(TimelinePage);
}, error => {
this.showError("Access Denied");
});
}
loginkeyboard() {
this.keyboard.onKeyboardShow().subscribe(
data => {
if(document.getElementById('login')){
document.getElementById('login').style.height = this.height + 'px';
}
}
);
}