简体   繁体   中英

Existing solutions not working- (AWS Lambda Api) The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true'

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?

Ensure the OPTIONS resource is enabled in your API Gateway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM