Categories
JavaScript Answers

How to fix ‘CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true’ with Express and JavaScript?

Spread the love

To fix ‘CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true’ with Express and JavaScript, we can change the config of the cors middleware.

For instance, we write

const app = express();
const corsConfig = {
  credentials: true,
  origin: true,
};
app.use(cors(corsConfig));

to set the credentails and origin options to true when we add the cors middleware in our Express app to avoid this error.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *