I’m trying to use the mattermost-redux Client4 API in a basic React app to interact with a Mattermost server located elsewhere. My code looks something like this:
import { Client4 } from "mattermost-redux/client"
...
Client4.setUrl('https://myserver.com');
...
await Client4.login(username, password);
The result is this error:
Access to fetch at 'https://myserver.com/api/v4/users/login' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
I’ve used the Mattermost System Console to set Enable cross-origin requests from:
to *
but no luck.
However, when I add the following to the index.html file for my React app:
fetch('https://myserver.com/api/v4/users/login', {
method: "POST",
body: JSON.stringify({login_id:"myusername", "password":"mypassword"})
})
...
…it works fine. No errors, and I get back readable JSON about my user account.
What am I missing?