Skip to main content
With Actions, you can extend passwordless connections by routing SMS and email OTP delivery through custom providers. Auth0 Actions give you control over which phone and email services handle your authentication messages.

Send passwordless email with a custom email provider

When a user authenticates through a passwordless email connection, Auth0 triggers the custom-email-provider Action to deliver the OTP. Use this Action to route messages through any email service. To configure the Action, navigate to Branding > Email Provider and select the Custom Provider option. To learn more, read Configure an Email Provider with a Customized Action.
/**
 * Handler called when Auth0 needs to deliver a passwordless email OTP.
 * @param {Event} event - Details about the notification.
 * @param {CustomEmailProviderAPI} api - Methods for controlling notification behavior.
 */
exports.onExecuteCustomEmailProvider = async (event, api) => {
  try {
    const response = await fetch('https://api.example.com/send-email', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${event.secrets.API_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        to: event.notification.to,
        from: event.notification.from,
        subject: event.notification.subject,
        html: event.notification.html,
        text: event.notification.text,
      }),
    });

    if (response.status >= 500) {
      api.notification.retry(`Server error from email provider: ${response.status}`);
      return;
    }
  } catch (error) {
    api.notification.drop(`Unexpected error: ${error.message}`);
  }
};
To learn more about available event properties, read Actions Triggers: custom-email-provider - Event Object.

Send passwordless SMS with a custom phone provider

When a user authenticates through a passwordless SMS connection, Auth0 triggers the custom-phone-provider Action to deliver the OTP. Use this Action to route messages through any SMS provider. To configure the Action, navigate to Branding > Phone Provider and select the Custom option. To learn more, read Configure a Custom Phone Provider.
/**
 * Handler called when Auth0 needs to deliver a passwordless SMS OTP.
 * @param {Event} event - Details about the notification.
 * @param {CustomPhoneProviderAPI} api - Methods for controlling notification behavior.
 */
exports.onExecuteCustomPhoneProvider = async (event, api) => {
  const response = await fetch('https://api.example.com/messages', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${event.secrets.API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      to: event.notification.recipient,
      from: event.notification.from,
      body: event.notification.as_text,
    }),
  });

  if (!response.ok) {
    api.notification.retry(`Failed to send SMS: ${response.status}`);
  }
};
To learn more about available event properties, read Actions Triggers: custom-phone-provider - Event Object.

Learn more