"Access to XMLHttpRequest at 'http://localhost:8080' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status."
This is the error I get when i try to login through basic authentication in spring security. @CrossOrigin() annotation is included in rest controller. But still i get this message. I've also tried @CrossOrigin(origins = { "localhost:4200"}, allowedHeaders={"Accept"}), still the message is shown whenever i try to login.
Angular method to authenticate:(I'm returning the logged in user id in rest controller)
authenticate(username, password) {
const headers = new HttpHeaders({ Authorization: 'Basic ' + btoa(username + ':' + password) });
return this.http.get<number>('http://localhost:8080/hiring-prediction-tool/users/login', {headers})
.pipe(map(
userData => {
console.log(userData, 'userData');
sessionStorage.setItem('username',username);
let authString = 'Basic ' + btoa(username + ':' + password);
sessionStorage.setItem('basicauth', authString);
return userData;
}
)
);
}