0

Code;

this.http.post(this.endpoint + "api/auth/signin", {"username": handle, "password": password}).subscribe(r => {
        // @ts-ignore
        if (r["status"] === "authorized") {
          localStorage.setItem("status", "signed_in")
          // @ts-ignore
          localStorage.setItem("token", r["token"])
        }
      })

Errors;

signin:1  Access to XMLHttpRequest at 'apiurl' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
signin:1  Access to XMLHttpRequest at 'apiurl' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

Server has these headers just for testing;

header('HTTP/1.1 200 OK')
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');

And the funny thing is when I add xmlrequest function to the console it works but not on angular version of ionic framework. I am going nuts. Please help...

devsimsek
  • 13
  • 1
  • 6
  • The _preflight_ request is made using the `OPTIONS` request method, and your server needs to respond to that with the CORS headers and status code 200 OK. Is that actually happening in your system? – CBroe Apr 24 '23 at 06:48
  • No, according to the error message that was half hidden behind a scroll bar, it is not: _"Response to preflight request doesn't pass access control check: It does not have HTTP ok status."_ – CBroe Apr 24 '23 at 06:49

1 Answers1

0

I've found the problem. Since I was paranoid about security I was blocking every request :)

devsimsek
  • 13
  • 1
  • 6