CORS error
-
I’m working with the miniOrange API authentication plugin locally in a headless wordpress set up with a React frontend. Making authenticated request for fetching and utilizing the token, works fine when tested on Postman, but when I run the implementation in the React app I get a CORS pre-flight error when trying access the API using Basic auth or JWT tokens
Using JWT authentication, I can successfully fetch the tokens but when I pass the tokens in the Bearer, I get the error above.
Here is my .htaccess:
# BEGIN WordPress # The directives (lines) between "BEGIN WordPress" and "END WordPress" are # dynamically generated, and should only be modified via WordPress filters. # Any changes to the directives between these markers will be overwritten. <IfModule mod_rewrite.c> RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /wordpress/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L] Header set Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, PATCH, DELETE" Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Credentials "true" Header set Access-Control-Allow-Headers "X-Accept-Charset,X-Accept,Content-Type,Credentials" </IfModule> # END WordPress # BEGIN enable-cors # The directives (lines) between "BEGIN enable-cors" and "END enable-cors" are # dynamically generated, and should only be modified via WordPress filters. # Any changes to the directives between these markers will be overwritten. <IfModule mod_headers.c> <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css|css|woff2)$"> Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Credentials "true" </FilesMatch> </IfModule> # END enable-cors
Initially I was getting a cors preflight Access-Control-Allow-Origin error but when I passed this values in the .htaccess and installed ENABLE CORS plugin it changed to the error I displayed above: Screenshot-2023-05-31-082317.png (640×69) (ibb.co)
- The topic ‘CORS error’ is closed to new replies.