Current solutions are ineffective - (AWS Lambda API) The 'Access-Control-Allow-Credentials' header value in the response is empty, but it should be set to '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 successfully!`,
      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)
}).catch((err)=>{ console.log(err," error")})

I have seen many posts on this topic, but none of them worked in my case. I have enabled CORS and integrated a proxy to my API Gateway. The options method is not a mock, it is integrated with my Lambda function.

CORS Values

 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 can I resolve this issue?

Answer №2

Make sure to activate the OPTIONS endpoint within your API Gateway configuration.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Pass the response from a MySql query executed in ExpressJS to a basic JavaScript file that is responsible for modifying the

I am currently utilizing ExpressJS as my server and MySql as my local database. However, I am facing a challenge in retrieving data from a specific table and sending the query result to either a vanilla JS file or directly editing HTML through NodeJS. Her ...

What is the best way to execute npm command in Visual Studio Code?

After successfully installing node.js on my local computer, I attempted to use the npm command in Visual Studio Code. Strangely, whenever I try a command like npm run start for React, I receive an error message stating: 'npm' is not recognized as ...

Is there a way to effectively deploy a node.js application on Azure using git when the application is located within a subfolder?

I have an existing git repository for a solution consisting of multiple projects, both .Net and Node.js. My goal is to use git to deploy certain projects to Azure Web sites. Deploying an ASP.Net project located in a subfolder was a breeze thanks to Scott ...

The latest entries are not visible on Mongoose unless the page is refreshed

There is a router with handlers for GET and POST requests related to documents. When creating new documents and posting them, the redirection works smoothly. However, upon initial page load after creation, only existing documents are displayed. It's o ...

Is the JSON parsing issue being caused by Bodyparser?

I am encountering an issue with parsing JSON on my server using the body-parser NPM module and Express. The JSON data is not appearing correctly on the server for some reason. Here is a snippet of my server code: ... app.use(bodyParser.json()); app.use(bo ...

Transferring form data from Jade to Node.js for submission

My Jade template includes the following form structure: form(action='/scheduler/save/' + project.Id, method='post') div.form-group label.control-label.col-md-2 RecurringPattern di ...

Running a fetch operation in Node results in receiving a status code of 464, while the same

I'm trying to request a URL using fetch in my node application, but the response status is returning as 464 without any responseText or error message. I've searched everywhere for information on this issue with no luck. Interestingly, when I tr ...

Error executing generateservertestreport script in npm run script

While executing an npm script through a TFS build, I encounter an issue. However, running the same script directly on the TFS build machine does not show any errors. Note: My node version is 8.12.0 and npm version is 6.4.1 Despite researching the cause o ...

I am having trouble running a Python script within an Express application

I have a Python script that turns on an LED on my Raspberry Pi, and I want to execute it when a button is clicked on my Express app. I've tested the script and it works fine, but for some reason, when I try to run it from the server, it doesn't w ...

What is the best way to make `npm prune --production` work in a recursive manner?

It seems like a simple task, yet I am unable to find any information online. When running npm prune --production, it only removes the direct devDependencies from the current package's node_modules folder. Unfortunately, it does not recursively remove ...

Different ways to alter response headers using express-http-proxy

Context In my current project, I am utilizing the express-http-proxy package to facilitate requests between a Single Page Application (SPA) and a CouchDB instance. I have opted for handling this proxy setup on a per call basis rather than creating a dedic ...

Should I include one of the dependencies' dependencies in my project, or should I directly install it into the root level of the project?

TL;DR Summary (Using Lodash as an example, my application needs to import JavaScript from an NPM package that relies on Lodash. To prevent bundling duplicate versions of the same function, I'm considering not installing Lodash in my application' ...

Passport authentication leading to incorrect view redirection in Express

I'm struggling to understand why the URL is updating but leading to the incorrect view. Once a user is authenticated with passport, the URL changes to my code (/clients) but it redirects back to the homepage view. After authentication, I want the us ...

What is the best way to implement record updates in a nodejs CRUD application using prisma, express, and typescript?

Seeking to establish a basic API in node js using express and prisma. The schema includes the following model for clients: model Clients { id String @id @default(uuid()) email String @unique name String address String t ...

How to read a config file using Node.js in an HTML file

In my configuration file, I have stored all the necessary settings. app: { root: 'rooturl' } I also have an HTML file that serves as a template. My goal is to access the config file from within the HTML file. <img src='rooturl&apos ...

Trouble arises in TypeScript when defining a class - SyntaxError crops up

When I try to declare a class, I encounter an error: // The code below is from my test1.ts file class WDesign { wModel: string; wQuer: string; } let logWDesign = (wd : WDesign) => { console.log(wd.wModel + " " + wd.wQuer); } let wd1 : WDe ...

Navigating through an array containing references to object IDs with Mongoose

In my meanjs project, I am receiving user input on the server with a specific request body structure: { transaction: { heading: '', items: [Object] }, something: {}, somethingAgain: {} } The format of the items a ...

Collaborating on interconnected documents: population dynamics and sophisticated modeling techniques

As someone who is fairly new to these technologies, I'm unsure if I am doing this correctly. I am attempting to display the name of the category in the table instead of the id (which is from the ObjectId schema field) for all the Category documents r ...

Executing a serverless function in Next.js using getStaticPaths: A step-by-step guide

In my current project, I am utilizing Next.js and the Vercel deployment workflow. To set up page generation at build time, I have been following a guide that demonstrates how to generate pages based on an external API's response. // At build time, t ...

What steps should I follow to obtain the return value after invoking these functions?

I have a task that requires creating a nodejs script for two specific functions: Retrieve my public IP address. Update my public IP address on my freenom.com account for a registered domain. Currently, I have two separate scripts in place to accompl ...