Delegated Administration Hooks: The Write Hook
The Write Hook, which runs anytime you create or update a user, allows you to do things like:
- Changing the user's password
- Changing the user's email address
- Updating the user's profile
You can also use the Write Hook to set default values for newly-created users automatically. For example, you might want to automatically assign a user to the same group, department, or vendor as the ones to which you've been assigned.
The Hook Contract
- ctx: The context object.
- request.originalUser: The current user's values where the payload is the new set of fields. Only available when the method is update
- payload: The payload object
- memberships: An array of memberships that were selected in the UI when creating the user
- email: The email address of the user
- password: The password of the user
- connection: The name of the database connection
- app_metadata: The data that's included if a Custom Field being modified is saved in
- user_metadata: The data that's included if a Custom Field being modified is saved in
- userFields: The user fields array (if specified in the settings query)
- method: Either create or update depending on whether this is being called as a result of a create or an update call
- callback(error, user): The callback to which you can return an error and the user object that should be sent to the Management API
Kelly manages the Finance department. When she creates users, these users should be assigned as members of the Finance department.