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 create an authentication trigger in the Realm UI:

  1. Click Triggers under MongoDB Cluster in the left navigation menu.
  2. Select the Authentication Triggers tab.
  3. Click Add Authentication Trigger in the top right to open the trigger configuration page.
  4. Enter configuration values for the trigger and click Save at the bottom of the page.

Authentication Triggers have the following configuration parameters:

Trigger Type
Required. The type of the trigger. For authentication Triggers, this value should be set to AUTHENTICATION.
Trigger Name
Required. The name of the trigger.
Linked Function
Required. 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
Required. The authentication operation type that causes the trigger to fire. The operation type must be formatted as a fully-capitalized string, e.g. "LOGIN".

Required. A list of one or more authentication provider types. The Trigger will only listen for authentication events produced by these providers.

The following values are valid:

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

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 TypeDescription
LOGINRepresents a single instance of a user logging in.
CREATERepresents the creation of a new user.
DELETERepresents the deletion of a user.

Authentication event objects have the following form:

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

The authentication providers that emitted the event.

One of the following names represents each authentication provider:

  • "oauth2-apple"
  • "oauth2-google"
  • "oauth2-facebook"
  • "custom-token"
  • "local-userpass"
  • "api-key"
  • "anon-user"
Info With Circle IconCreated with Sketch.Note

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.

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