Auth dialog Events

Auth dialog is used to capture new auths from your end users. The dialog window posts some events to the global window object that can be captures to take further actions.

You can attach a message event listener to the window where user's click on create auth button.

window.addEventListener("message", onmessage);

By doing this, you will be able to capture the messages sent by the auth popup window.

The three events you would want to capture from the window are:

  • tray.authPopup.error This event is fired when the auth dialog runs into unexpected errors (ex. mismatched service environment ID and service ID)
  • tray.authpopup.close This event is fired when the auth dialog is closed by the user abruptly
  • tray.authpopup.finish This event is fired when the user provides the auth details and the popup window closes by itself. This event would contain the authId of the newly created auth. Here's how this event's data would look:
  "type": "tray.authpopup.finish",
  "authType": "oauth",
  "authId": "1209xxxx-xxxx-xxxx-xxxx-xxxxxx8d3779"

Here is a sample code on how you could structure your authWindow function:

export const openAuthWindow = (url) => {
  // Must open window from user interaction code otherwise it is likely
  // to be blocked by a popup blocker:
  const authWindow =
  const onmessage = (e) => {
    if ( === "tray.authPopup.error") {
      // Handle popup error message
      alert(`Error: ${}`);
    if ( === "tray.authpopup.close" || === "tray.authpopup.finish"
    ) {
  window.addEventListener("message", onmessage);

  // Check if popup window has been closed
  const CHECK_TIMEOUT = 1000;
  const checkClosedWindow = () => {
    if (authWindow.closed) {
      window.removeEventListener("message", onmessage);
    } else {
      setTimeout(checkClosedWindow, CHECK_TIMEOUT);

  authWindow.location = url;

const authDialogURL = `https://${AUTH_DIALOG_URL}/external/auth/create/${PARTNER_NAME}?code=${}&serviceId=${serviceId.current}&serviceEnvironmentId=${}&scopes[]=${scopes}`;


You can also check the code of the form builder app to see how it's implemented there.