Authentication Triggers

Authentication triggers allow you to execute server-side logic whenever a user interacts with an authentication provider. You can use authentication triggers to implement advanced user management, including storing new user data in your linked cluster, maintaining data integrity upon user deletion, or calling a service with a user’s information when they log in.

To open the authentication trigger configuration screen in the Realm UI, click Triggers in the left navigation menu, select the Authentication Triggers tab, and then click Add a Trigger.

Configure the trigger and then click Save at the bottom of the page to add it to your current deployment draft.

An authentication trigger has the following configuration options:

Trigger Type
The type of the trigger. For authentication triggers, this value should be set to AUTHENTICATION.
Trigger Name
The name of the trigger.
Linked Function
The name of the Realm Function that the trigger executes whenever it fires. The trigger passes the authentication event object that caused it to fire as the only argument to this function.
Operation Type
The authentication operation type that causes the trigger to fire.
A list of one or more authentication provider types. The trigger will only listen for authentication events produced by these providers.

Authentication events represent user interactions with an authentication provider. Each event corresponds to a single user action with one of the following operation types:

Operation Type
Represents a single instance of a user logging in.
Represents the creation of a new user.
Represents the deletion of a user.

Authentication event objects have the following form:

"operationType": <string>,
"providers": <array of strings>,
"user": <user object>,
"time": <ISODate>
The operation type of the authentication event.

The authentication providers that emitted the event.

One of the following names represents each authentication provider:

  • "anon-user"
  • "local-userpass"
  • "api-key"
  • "custom-token"
  • "custom-function"
  • "oauth2-facebook"
  • "oauth2-google"
  • "oauth2-apple"

Generally, only one authentication provider emits each event. When a you delete a user linked to multiple providers, the DELETE event for that user includes all linked providers.

The user object of the user that interacted with the authentication provider.
The time at which the event occurred.
Give Feedback