(!) Issue cannot be reproduced locally.
Azure Function Version ~4
Node Version 14.18.1
Creating a simple HTTP triggered Azure Function and setting just two simple properties we get the following code:
module.exports = async function (context, req) {
req.auth = {authField: 'some value'}
req.user = {userField: 'some value'}
context.log(`${JSON.stringify(req,null,2)}`);
context.res = {
body: 'responseMessage'
};
}
The logger prints the following object:
{
"method": "POST",
"url": "xxx",
"originalUrl": "xxx",
"headers": {
/// ...
},
"query": {},
"params": {},
"body": { "name": "Azure" },
"rawBody": "{\"name\":\"Azure\"}",
"auth": { "authField": "some value" }
}
As you see only auth
is set and not user
.
The same failing behavior can be seen in version 4.2.0
.
When I test with Azure Function ~3 the output looks like this:
{
"method": "POST",
"url": "xxx",
"originalUrl": "xxx",
"headers": {
// ...
},
"query": {},
"params": {},
"body": { "name": "Azure" },
"rawBody": "{\"name\":\"Azure\"}",
"auth": { "authField": "some value" },
"user": { "userField": "some value" }
}
As you see the field is set.
The following custom v4 4.1.0-17156
also sets the user
field.
The field user
was used by us through the express-jwt (v6.1.0) which is using it when no value is provided for requestProperty
.
I could not yet reproduce it but in out transpiled from Typescript project, we get the following runtime error:
FailureException: Cannot set property user of [object Object] which has only a getterStack: TypeError: Cannot set property user of [object Object] which has only a getterat Object.run
The issue started at the beginning of the day of 26th of April 2022.
Questions:
- what is the reason?
- is a quick roll back to the functioning Azure Function custom version possible?
I found the culprit in this PR, which was added for Azure Function runtime v4.2.0.
The user field was added with only a getter.
We took the code and made the minimal example:
and got the following transpilied version:
So, it always returns the the initial value, which in our example is "some value" but in the original code is simply
undefined
and does not allow to set it.