usefulteam / jwt-auth

WordPress JSON Web Token Authentication
https://wordpress.org/plugins/jwt-auth/
122 stars 48 forks source link

CORS Issue #24

Open dandin84 opened 3 years ago

dandin84 commented 3 years ago

Hi,

I installed the plugin on a new clean Wordpress on localhost environment. I am trying to create a login via local React app and get CORS errors. I understand the reason but do you know how can I get through it?

htaccess image

wp-config image

wp-admin image

react call image

error image

request image

Thanks, Daniel

a-prods commented 3 years ago

Same issue, any solution / work around?

dominic-ks commented 3 years ago

This is my general approach to CORS on WP in case it's helpful, this goes in a custom plugin ideally, or theme functions.php may also work but I've not tested it.

function my_cors_domains( $allowed_origins ) {
  $allowed_origins[] = 'http://localhost:4200';
  $allowed_origins[] = 'whatever-else';
  return $allowed_origins;
}

add_filter( 'allowed_http_origins' , 'my_cors_domains' , 10 , 1 );