Cors error in nestjs. it is not working withCredentials


I am getting below error while using "{withCredentials:true}" in the API .if I am not using this then it is not working.

const submit = async(e:SyntheticEvent) =>{
    e.preventDefault();
    await axios.post('http://localhost:8000/api/login',{
        email,
        password
    });
}

the above is working properly. When I am using {withCredentials:true} then it is giving cors() error.

const submit = async(e:SyntheticEvent) =>{
    e.preventDefault();
    await axios.post('http://localhost:8000/api/login',{
        email,
        password
    },{withCredentials:true}); 
    setRedirect(true);

enter image description here

}

in main.ts file I have below configurations.

  const options = {
    origin: '*',
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
    preflightContinue: false,
    credentials: true,
  };
  app.enableCors(options);

even I tried credentials: false, still it is not working.

I have to use {withCredentials:true} so that I can take jwt tokens for authorizations.

Source: React – Stack Overflow

November 20, 2021
Category : News
Tags: cors | nestjs | nestjs-config | node.js | reactjs

Leave a Reply

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

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.