Background functions provide a clientContext and user locally, but not in production #4383
Labels
area: command: dev
area: functions
good first issue
type: bug
code to address defects in shipped code
Describe the bug
Background functions don't check for an authorization header token in production, so there's never a
clientContext
or any way to validate that an Identity authenticated user is sending the request. This isn't documented, but it's mentioned in a community answer: https://answers.netlify.com/t/clientcontext-user-missing-in-background-functions/46166/2This can be hacked around pretty simply (I'm using a regular function to auth and then passing a secret to the background function), but it's a surprise when Netlify Dev does authenticate requests to background functions. So you put your authenticated background function live, it fails in production, and then you can't see why because background functions don't provide logs 🙈 (except sometimes they do??)
I can open a PR to simply remove
clientContext
for background functions here, which I’ve validated locally, but I didn't see an obvious way to test the inner workings of background functions in the current testing setup. Happy to open a PR with just the fix, or with tests too if anyone has thoughts on how to go about it.To Reproduce
Steps to reproduce the behavior:
context.clientContext.user
in the handlerExpected behavior
context.clientContext
should be nullish, matching productionThank you for making the cli amazing! While no pictures of animals were requested, I've provided complimentary hippos.
The text was updated successfully, but these errors were encountered: