I am trying to write an Azure Function which will set a HttpOnly cookie in the user's browser but it is not working. In Postman I can see the Set-Cookie header in the response, but this header is omitted when testing the function in the browser.
Here are the Headers returned to the browser:
headers: {content-length: "13", content-type: "text/html; charset=utf-8"}
Here is my code:
Azure Function Code
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
context.res = {
status: 200,
headers: {
"Content-Type": "text/html",
"Set-Cookie": "a=b; httpOnly",
},
body:
'Body Response'
};
context.done();
}
Node Code
const createCookieAzure = () => {
return new Promise((resolve, reject) => {
console.log("Inside create cookie promise");
axios({
url: 'http://localhost:7071/api/SetHttpOnlyCookie',
method: 'GET',
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
})
}
const createHttpOnlyCookie = async (e) => {
e.preventDefault();
console.log("Button clicked");
await createCookieAzure();
console.log("After createcookie");
}
In the above code createHttpOnlyCookie() is triggered by the onClick of a button component.