Navigation

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:

Field
Description
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.
Providers
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
Description
LOGIN
Represents a single instance of a user logging in.
CREATE
Represents the creation of a new user.
DELETE
Represents the deletion of a user.

Authentication event objects have the following form:

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

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"
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.

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