Sync Gateway check if admin call(superuser)

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.

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.

1 Like

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

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

1 Like