-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add new afterLogin cloud code hook #6387
Add new afterLogin cloud code hook #6387
Conversation
This is the PR for the |
Hey @davesters this is good stuff, I definitely see the use for it, and it rounds off the user's expectation of before/after hook pairing. I've only reviewed the test-cases so far and would like clarification on one point Your I'm not sure if the user as set on |
Thanks @omairvaiyani for the feedback. Currently, the user is available on the In terms of the session token, that is an interesting point. I left it in there because I need it for my specific use case, but I can see a good argument for taking it out. In which case, I could do a quick query inside the hook to look up the new session token for the user for my use case. I will leave it alone for right now and wait for some additional feedback, but I am open to any of these changes as I think they do make sense. Thanks! |
Sorry I think I might have given the wrong idea! My final point was that having the session token within |
Nicely done. Super simple. req.user should be there as it is the user that made the requests. Even if it is a new user. |
Codecov Report
@@ Coverage Diff @@
## master #6387 +/- ##
==========================================
- Coverage 93.98% 93.85% -0.14%
==========================================
Files 169 169
Lines 11687 11694 +7
==========================================
- Hits 10984 10975 -9
- Misses 703 719 +16
Continue to review full report at Codecov.
|
Thanks @omairvaiyani and @dplewis for the feedback. I have made a quick change to include the user object on the Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dplewis it looks good to me. Do you also want to take a look?
* add new afterLogin cloud code hook * include user on req.user for afterLogin hook
This PR adds a new
afterLogin
cloud code hook. I referenced the pull request adding thebeforeLogin
hook done by @omairvaiyani quite heavily for this PR, so it was implemented in a very similar manner.Currently there is no method to do any work after a user has successfully logged in, and Parse Server does not allow hooks on
_Session
objects.Use cases:
Motivation:
In my specific case, we have an API gateway and authentication service in other areas of our system. This uses Parse authentication and user sessions when necessary for Parse users. We have a need to keep track of Parse Sessions in other areas of our system, so with this new hook we are able to send events when a new session is created on login that can be consumed by our other services. We also use the
afterLogout
hook when sessions are deleted as well.Example usage: