skip to Main Content

my lambda function

    module.exports.handler = async(event, context, callback) => {
  
  return { statusCode: 200,
        headers: {
          "Access-Control-Allow-Credentials" : 'true',
          'Access-Control-Allow-Origin': 'mydomain_name',
          'Access-Control-Allow-Methods':'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT',
          'Access-Control-Allow-Headers':'content-type,authorization',
          
        },
        body: JSON.stringify({
          message: `Charge processed succesfully!`,
          success:true,
         
        }),
}
}

error -"

The value of the ‘Access-Control-Allow-Credentials’ header in the response is ” which must be ‘true’ when the request’s credentials mode is ‘include’. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

Frontend

 const config = {
        headers: { 'Authorization': 'Bearer ' + Message.cookey_key, "Content-Type":'application/json',withCredentials:true, credentials: 'include' },
        
      };
      await PaymentAppApi.post(`/`,payment_item,config).then((res)=>{
         
         
         responseData = res.data
         console.log(res)
         //console.log(res.data[0]+" cal ki hoi na !!! , , ,!"+res.data)
        
    }).catch((err)=>{ console.log(err," error")})

I have seen so many posts on this particular topic. But none of them worked in this case. I have enabled cors and integrated poxy to my api gateway. Option method is not a mock . It is integrated with my lambda function.

Cors value

 Access-Control-Allow-Methods : 'DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT' 
`Access-Control-Allow-Headers  : 'COntent-Type, Authorization'
 Access-Control-Allow-Origin*  : 'mydomain_name'
 Access-Control-Allow-Credentials : 'true'

How may I fix this issue?

2

Answers


  1. Ensure the OPTIONS resource is enabled in your API Gateway.

    Login or Signup to reply.
  2. You should set the Access-Control-Allow-Credentials header to true (boolean value) instead of 'true' (string value). That header does not recognize anything other than the boolean true.

    Related MDN article: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials#directives

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search