Authorize user
Server scripts are used to implement authorization rules to make sure that authenticated users can only see their own data or granting additional capabilities to administrators.
Important: To be able to authenticate users, you must register your app with an identity provider. You must then register the provider-generated client secret with Mobile Services. For more information, see Get started with users (Windows Store/Windows Phone/iOS).
The following example sets the owner property based on the userId of an authenticated user.
function insert(item, user, request) {
item.owner = user.userId;
request.execute();
}
The following example adds an additional filter to the query based on the userId of an authenticated user. This filter restricts the result to only items that belong to the current user.
function read(query, user, request) {
query.where({
owner: user.userId
});
request.execute();
}
For more information, see the Mobile Services script reference