I noticed that
context.user
in system functions doesn't always work as documented.
For example, the documentation states that "You can dynamically reference the active user of a Function in the Function’s source code with context.user." (https://docs.mongodb.com/stitch/functions/#active-user) and that "A System Function is a Function where the active user is a system user instead of an application user." (https://docs.mongodb.com/stitch/functions/#system-functions). However, when I run a system function as a logged in user with the browser SDK,
context.runningAsSystem()
returns
true
and
context.user
is the logged in user, not a system user.
When I run the same system function using the Stitch UI, it works as documented: If it's run as a user, the active user is set correctly and the function doesn't run with system privileges, i.e.,
context.runningAsSystem()
returns
false
.
Which behavior is correct? Can I rely on the
context.user
object containing information about the user who called the system function or is that a bug in Stitch?
I created a reproduction repository here: https://github.com/klaussner/stitch-system-function-reproduction.