redux_jwt_auth
redux_jwt_auth copied to clipboard
CORS issue
@gitdagray Thanks for the tutorial and code. It really helps.
I faced CORS issue if we use "credentials: 'include'" when the server has allow orgin as "*". Since we are using API Tokens, do we need this flag? Can we change it to "credentials: 'omit'" ? (Since this flag is only need for cookies)
https://github.com/gitdagray/redux_jwt_auth/blob/44f187232124b9a23398169bdfe97068299a362b/src/app/api/apiSlice.js#L6
@gitdagray Thanks for the tutorial and code. It really helps.
I faced CORS issue if we use "credentials: 'include'" when the server has allow orgin as "*". Since we are using API Tokens, do we need this flag? Can we change it to "credentials: 'omit'" ? (Since this flag is only need for cookies)
https://github.com/gitdagray/redux_jwt_auth/blob/44f187232124b9a23398169bdfe97068299a362b/src/app/api/apiSlice.js#L6
Kindly change include to true
@gitdagray Hi, I followed your tutorials on youtube (very helpful btw) and I'm hitting the CORS issue. I've tried the following:
- Changing credentials: "include" to credentials: "same-origin"
- Adding "proxy": "
in package.json file - Adding http-proxy-middleware as suggested in https://jafreitas90.medium.com/how-to-solve-the-cors-issue-in-a-create-react-app-project-with-a-proxy-5403141d7f32
In the 3rd method, I am getting the following error:
{
"status": "PARSING_ERROR",
"originalStatus": 404,
"data": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot POST /api/path</pre>\n</body>\n</html>\n",
"error": "SyntaxError: Unexpected token '<', \"<!DOCTYPE \"... is not valid JSON"
}
But nothing seems to work. Is there something I'm missing? Would really appreciate it if I could get some help.
NOTE: I have a grpc server.
@gitdagray Thanks for the tutorial and code. It really helps.
I faced CORS issue if we use "credentials: 'include'" when the server has allow orgin as "*". Since we are using API Tokens, do we need this flag? Can we change it to "credentials: 'omit'" ? (Since this flag is only need for cookies)
https://github.com/gitdagray/redux_jwt_auth/blob/44f187232124b9a23398169bdfe97068299a362b/src/app/api/apiSlice.js#L6
Any luck in finding the solution?
const baseQuery = fetchBaseQuery({
baseUrl: "http://localhost:8000/api",
prepareHeaders: (headers, { getState }) => {
headers.set("Access-Control-Allow-Headers", "*");
const token = getState().auth.token;
if (token) {
headers.set("Authorization", `Bearer ${token}`);
}
return headers;
},
});
In my case i used
headers.set("Access-Control-Allow-Headers", "*");
I think it will be solve the issue :)