Sync Gateway check if admin call(superuser)


#1

Hi guys,

Can you tell me how can I check in a sync function that the current create/update is coming from a public or admin rest call? The usecase is simple, I would like to allow specific documents to be created only through the admin port(automatically created by a script who lives on the server)

Thank you.


Sync Function and shared_bucket_access
#2

When requests come in the admin port, the authorizing users sync function calls such as (requireUser, requireRole, requireAccess, etc) are all “no-ops” and they have no effect.

So if you add requireRole("someNonexistentRole") to your sync function handling for those specific docs, then it will only work over the admin port, and will otherwise be rejected.


#3

That is a good idea, I will use this solution. Thank you!


#4

@martinconic Well, this sounded like a nice feature to have, so…