Closed kpfromer closed 7 years ago
@kpfromer The answer is the scope for your user does not contain "user-5a061e8b51742324957e72bb". When you login you can see your user's scope at the bottom of the response.
This is actually something I meant to add in earlier to appy but forgot. I just pushed an update with the appropriate functionality to add "user-{_id}" to a user's scope upon login. If you pull the latest version of appy this should work for you and you won't receive the "Insufficient scope" error.
@JKHeadley I was under the impression that all routes would automatically check for request.auth.credentials.user._id
and then compare. Thanks for adding the feature.
Adding to this issue is there any way to remove the following if the user doesn't own it? It might cause issues for the frontend since it will have to remove every object that contains an Insufficient document scope
error.
{
"error": "Insufficient document scope."
}
@kpfromer That's one of ways it could be implemented. The docs show a similar method. You can create a policy to implement it differently if you like. The default method uses scopes only.
The response objects are replaced with the error to prevent pagination issues. If you need to remove them, I would suggest creating a policy that filters out all the error objects. This was a tricky problem to deal with. I'm certainly open to any suggestions if you feel there is a better solution.
@JKHeadley How would one get what is going to return in the "doc" payload? I am trying to create an onPostHandler
policy but don't know what to modify or get in the request
parameter of policy achieve this functionality.
@kpfromer you can access the response through "request.response.source", so the docs would be "request.response.source.docs".
I am using an onPostHandler
policy and then I am reading the request.response.source.docs
but it only returns the valid items, not the ones that have errors.
I fixed the issue, I needed to use an onPreResponse
policy. At the point the policy is runned the errors are in the doc and can be removed.
So I am at the point where I want to set authorizeDocumentCreator to true. I have done so by adding
enableDocumentScopes: true
andauthorizeDocumentCreator: true
to the config.js file, I have also dumped the database and reseeded it. I have created a simple model object for demonstration.When I log in and post a new task I am returned this
But when I try to get the task I encounter an error!
I don't know why I am getting
"error": "Insufficient document scope."
since I am using the same user account! Thanks, Kyle Pfromer