close

[Solved] CORS: credentials mode is ‘include’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error CORS: credentials mode is ‘include’ in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How CORS: credentials mode is ‘include’ Error Occurs?

Today I get the following error CORS: credentials mode is ‘include’ in javascript.

How To Solve CORS: credentials mode is ‘include’ Error ?

  1. How To Solve CORS: credentials mode is 'include' Error ?

    To Solve CORS: credentials mode is 'include' Error If it helps, I was using centrifuge with my reactjs app, and, after checking some comments below, I looked at the centrifuge.js library file, which in my version, had the following code snippet: if ('withCredentials' in xhr) {
    xhr.withCredentials = true;
    }

  2. CORS: credentials mode is 'include'

    To Solve CORS: credentials mode is 'include' Error If it helps, I was using centrifuge with my reactjs app, and, after checking some comments below, I looked at the centrifuge.js library file, which in my version, had the following code snippet: if ('withCredentials' in xhr) {
    xhr.withCredentials = true;
    }

Solution 1


If you’re using .NET Core, you will have to .AllowCredentials() when configuring CORS in Startup.CS.

Inside of ConfigureServices

services.AddCors(o => {
    o.AddPolicy("AllowSetOrigins", options =>
    {
        options.WithOrigins("https://localhost:xxxx");
        options.AllowAnyHeader();
        options.AllowAnyMethod();
        options.AllowCredentials();
    });
});

services.AddMvc();

Then inside of Configure:

app.UseCors("AllowSetOrigins");
app.UseMvc(routes =>
    {
        // Routing code here
    });

For me, it was specifically just missing options.AllowCredentials() that caused the error you mentioned. As a side note in general for others having CORS issues as well, the order matters and AddCors() must be registered before AddMVC() inside of your Startup class.

Solution 2

If it helps, I was using centrifuge with my reactjs app, and, after checking some comments below, I looked at the centrifuge.js library file, which in my version, had the following code snippet:

if ('withCredentials' in xhr) {
 xhr.withCredentials = true;
}

After I removed these three lines, the app worked fine, as expected.

Hope it helps!

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment