Trigger for Just-in-Time Membership
Last Updated:
Overview
When using the Organizations feature, this article explains whether there is there an Action trigger that a user has been added to an organization through just-in-time membership.
Cause
Solution
- If the Just-In-Time members will be logging in for the first time, a check of the user's "event.stats.logins_count === 1", can indicate it is the user's first login. If a first login is detected, perform an additional check if the user has an Organization assigned by inspecting the event.organization object:
- Alternatively, if a first time login is not necessarily aligned with the user's organization membership, a custom flag could be stored in the user's app_metadata, to indicate whether the membership process had been triggered for the user yet.
- If this custom flag flag was absent, check the user's organization details are present in the event.organization object. If the user has an organization set, then this can be considered a "Just In Time membership" event.
- After any additional business logic has been triggered, add the custom flag to the app_metadata via the Action's api, e.g.:
if (event.user.app_metadata.JIT_membership_processed) {
return; //exit early, already processed
} else {
if (event.organization) {
//Not processed yet and current login is in Organization context - begin JIT processing here and mark user as processed if successful using custom app_metadata flag
api.user.setAppMetadata("JIT_membership_processed", true)
}
}