-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
beforeLogin Hook #4524
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
beforeLogin Hook #4524
Conversation
…meone can run code to do extra validation, notification or logging
…meone can run code to do extra validation, notification or logging
Codecov Report
@@ Coverage Diff @@
## master #4524 +/- ##
==========================================
+ Coverage 92.9% 92.91% +<.01%
==========================================
Files 118 118
Lines 8448 8473 +25
==========================================
+ Hits 7849 7873 +24
- Misses 599 600 +1
Continue to review full report at Codecov.
|
src/RestWrite.js
Outdated
return validateAuthData(authData[provider]).then(() => { | ||
if (this.response) { | ||
// it is a login call | ||
runBeforeLoginHandler({ |
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.
As mentioned previously, the object passed to the beforeLogin hook should match the ones provided in other hooks like beforeSave http://parseplatform.org/Parse-SDK-JS/api/v1.11.0/Parse.Cloud.html#.TriggerRequest
The req.object property should be an instance of Parse.User, all the key types should match their proper types (createdAt/updatedAt as dates), authProvider don’t make sense on req.object but may be left on the top level.
We also expect all other keys like installationId, headers etc.. to be set
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.
Hi @flovilmart, sorry for the incomplete PR, I misunderstood your previous message. I am fixing it.
Thanks,
No need to be sorry! This happen!
Thanks for keeping up with it!
|
@carlosapgomes May I ask why this PR was closed? Could you summarise what you've achieved and which areas you need help with? I have a significant use-case for this in my application and look forward to seeing this accepted. |
@omairvaiyani If it's any assistance, this is on my TODO list that I hopefully will get to soon. I have a similar PR with before/after Session triggers that I hope to work on. Maybe even this week or the next if all goes well. |
@addisonElliott excellent, I'll watch this PR and help where possible |
Hi @omairvaiyani , I got to parse-server while looking for a nodejs framework to rewrite one of my web apps. One of my main needs was to have login hooks, and I thought that it could be implemented with parse-server's hooks infrastructure. |
@carlosapgomes Not a problem - I'm sure @addisonElliott will still find use in your commits |
@omairvaiyani did you give it a go? |
@flovilmart can you please say whats left in this PR? So, I can finish it asap, and use it in my current project? Its kinda urgent feature. |
@carlosapgomes please grant me access on your fork, so I can push commits. |
@haroonKhan-10p please open a new pull request. |
@haroonKhan-10p I would suggest opening a new pull request and if you use code from an existing PR, link to it and credit the author. As an FYI, I have a similar PR here #4020 that uses a different approach. I would recommend trying to merge and pick and place these two methods to get beforeLogin/afterLogin working. |
Any news on this? This would be a really great feature. |
+1 |
Re-attempted in this PR |
Hello @omairvaiyani, if I understand well, the #5445 is not the same PR, as it's not allowing you to have the auth providers @carlosapgomes was talking about in the first message here. |
Hello!
I am reopening PR #4513 with a
beforeLogin Hook
name.I think it relates to similar PRs: #4020 and #1016.
In my use case I need a way to add extra validation to the login process. To do that I think it is important to know who the user is but still be able to abort the whole login flow.
So, biased by my use case, I think that the definition of
beforeLogin
is not before the login process begins, but before it is completed, that is, the hook should be placed in a point on the login flow where the user has already had her credentials verified by parse-server, but before token creation.With that in mind, I added code to allow the following snippet to be called from the login process and still be able to throw errors that would abort it:
where
userLoginData
is an object:authProvider
is a string with the provider name (for login with authProvider) or justpassword
(for login with username/password).authData
is the same authData object available in the authProvider login flow and is an empty object for login with username/password.I wrote some tests in spec/BeforeLogin.spec.js, but I am pretty sure that they do not cover all possible side effects.
So I would like to ask for opinions and suggestions especially about the choices I made defining
beforeLogin
, the way it was implemented and about what other tests should I do.Thanks