That’s intentionally not possible. (There are cases where the doc has to be run through the sync function by internal maintenance processes, not by the user who modified the document; in that case a value like “currentUserID” would end up being null or otherwise non-useful.)
What you do instead is have the client app put the user’s ID into a document property, something like owner
. Then the sync function should call requireUser(doc.owner)
to validate that the user changing the document is the document’s owner. (This works even during maintenance, because in that mode requireUser()
is a no-op.)
Now you have the user’s ID in the doc.owner
property and can use it as in your snippet above, to derive a channel name.