Add new afterLogin cloud code hook (#6387)

* add new afterLogin cloud code hook

* include user on req.user for afterLogin hook
This commit is contained in:
David Corona
2020-02-11 17:38:14 -06:00
committed by GitHub
parent 8e195ef5ae
commit 09a1dca5e3
4 changed files with 145 additions and 7 deletions

View File

@@ -165,6 +165,42 @@ ParseCloud.beforeLogin = function(handler) {
);
};
/**
*
* Registers the after login function.
*
* **Available in Cloud Code only.**
*
* This function is triggered after a user logs in successfully,
* and after a _Session object has been created.
*
* ```
* Parse.Cloud.afterLogin((request) => {
* // code here
* })
*
* ```
*
* @method afterLogin
* @name Parse.Cloud.afterLogin
* @param {Function} func The function to run after a login. This function can be async and should take one parameter a {@link Parse.Cloud.TriggerRequest};
*/
ParseCloud.afterLogin = function(handler) {
let className = '_User';
if (typeof handler === 'string' || isParseObjectConstructor(handler)) {
// validation will occur downstream, this is to maintain internal
// code consistency with the other hook types.
className = getClassName(handler);
handler = arguments[1];
}
triggers.addTrigger(
triggers.Types.afterLogin,
className,
handler,
Parse.applicationId
);
};
/**
*
* Registers the after logout function.