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

feat: include sessionToken in onLiveQueryEvent #7043

Merged
merged 6 commits into from
Dec 4, 2020

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Dec 3, 2020

Closes #1906.

If a sessionToken is passed onLiveQueryEvent, lookup the associated Parse.User, and set req.user.

@codecov
Copy link

codecov bot commented Dec 3, 2020

Codecov Report

Merging #7043 (371abda) into master (c8ff445) will increase coverage by 0.03%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7043      +/-   ##
==========================================
+ Coverage   93.83%   93.86%   +0.03%     
==========================================
  Files         169      169              
  Lines       12439    12438       -1     
==========================================
+ Hits        11672    11675       +3     
+ Misses        767      763       -4     
Impacted Files Coverage Δ
src/LiveQuery/ParseLiveQueryServer.js 94.92% <ø> (ø)
src/triggers.js 94.60% <50.00%> (+0.89%) ⬆️
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 92.92% <0.00%> (-0.67%) ⬇️
src/Options/Definitions.js 100.00% <0.00%> (ø)
src/RestWrite.js 94.00% <0.00%> (+0.48%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c8ff445...371abda. Read the comment docs.

Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment and a nit

src/triggers.js Outdated Show resolved Hide resolved
src/triggers.js Show resolved Hide resolved
src/triggers.js Outdated Show resolved Hide resolved
spec/ParseLiveQuery.spec.js Show resolved Hide resolved
Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! I can't believe I missed this.

@dblythy
Copy link
Member Author

dblythy commented Dec 3, 2020

Thanks for the review! Shoutout to @maxiqsoft for identifying the solution.

@dplewis
Copy link
Member

dplewis commented Dec 3, 2020

@dblythy Actually I think passing the sessionToken should be enough. I don't know how I feel about doing a lookup for every live query event (could be hundreds of thousands of events). The developer can easily get the user from the sessionToken. What do you think @davimacedo

@dblythy
Copy link
Member Author

dblythy commented Dec 3, 2020

@dblythy Actually I think passing the sessionToken should be enough. I don't know how I feel about doing a lookup for every live query event (could be hundreds of thousands of events)

This might be worth considering for afterLiveQueryEvent trigger too, which fires on update, leave, enter, create delete, where onLiveQueryEvent fires on connect, subscribe, unsubscribe, ws_connect, ws_disconnect, ws_disconnect_error.

Currently, afterLiveQueryEvent looks up request.user.

@mtrezza
Copy link
Member

mtrezza commented Dec 3, 2020

I think with the installation ID and the session token now both being available, there are now 2 ways of inferring the user. A user lookup should be done optionally if needed, due to the look-up costs.

@dplewis
Copy link
Member

dplewis commented Dec 3, 2020

That’s probably why I didn’t add sessionToken here because installationId was enough.

@dblythy dblythy changed the title feat: include user in onLiveQueryEvent feat: include sessionToken in onLiveQueryEvent Dec 3, 2020
@mtrezza
Copy link
Member

mtrezza commented Dec 4, 2020

As I mentioned in the original tread #1906:

it would currently be possible to infer the user from the installationId, but that is indirect and requires additional referencing. This solution on the other hand would allow to infer the user directly from the session object.

So I think there is definitely an advantage of having the session token over the installation ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to detect a user is offline when using liveQuery in a realtime chat app
3 participants