Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject LiveQuery events / modify LiveQuery query in Cloud Code #6642

Closed
dblythy opened this issue Apr 24, 2020 · 3 comments
Closed

Reject LiveQuery events / modify LiveQuery query in Cloud Code #6642

dblythy opened this issue Apr 24, 2020 · 3 comments
Labels
type:feature New feature or improvement of existing feature

Comments

@dblythy
Copy link
Member

dblythy commented Apr 24, 2020

Is your feature request related to a problem? Please describe.
Is there a way to throw "onLiveQueryEvent"? I've restricted LiveQuerying using ACLs, however I'd like to prevent an unauthorised user from even attempting to subscribe to start. I'd also like to be able to force beforeFind logic to LiveQueries, to ensure the LiveQuery queries themselves are efficient and restrictive.

Describe the solution you'd like
Being able to throw from a onLiveQueryEvent, or being able to modify request.query from a LiveQuery.

@dplewis dplewis added enhancement type:feature New feature or improvement of existing feature labels Apr 24, 2020
@dplewis
Copy link
Member

dplewis commented Apr 24, 2020

I like this feature and it should be easy to add a trigger for this. How do you foresee the code looking for this?

You can look here for subscription handling.

@dblythy
Copy link
Member Author

dblythy commented Apr 25, 2020

Thanks mate. So it would have to be a new trigger? Something like afterLiveQueryEvent, which user can write cloud code - just like onLiveQueryEvent - but if an error is thrown, call Client.pushError? Not entirely familiar with the workings of LiveQuery code but will try create a PR.

@dblythy
Copy link
Member Author

dblythy commented Jul 17, 2020

Closing as beforeConnect and beforeSubscribe has been merged.

beforeConnect allows validation prior to a LiveQuery opening connection. This is not class specific.

Parse.Cloud.beforeConnect(request => {
      if (!request.user) {
          throw "Please login before you attempt to connect."
      }
});

beforeSubscribe handles the .subscribe methods from LiveQuery. Can be used to validate users, or to mutate the request.query, enforcing fields, equalTo, or whatever required.

Parse.Cloud.beforeSubscribe(Parse.User, request => {
    if (!request.user) {
        throw "Please login before you attempt to connect."
    }
    let query = request.query; // the Parse.Query
    query.select("name","year")
});

And via the JS-SDK:

Parse.LiveQuery.on('error', error => {
      alert(error)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

3 participants