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.