login_status

The login_status message is sent by myzPAX in response to a login status request. It indicates whether the user is currently authenticated. It returns the authenticated user’s ID (userId) when the user is logged in; otherwise, it returns null.

Message Type

type messageType = 'login_status';

Payload

// Contains the userId if the user is logged in; otherwise, the value is null.
type Payload = number | null;

When It Is Sent

  • In response to sendZpaxMessage('login_status') request.

Example

To check whether the session of the embedded application is still valid:

// During the app initialization
const removeListener = addZpaxMessageListener('login_status', (message) => {
  /**
   * Handles the SSO login status response from the myzPAX.
   *
   * message.data → number | null
   *
   * Meaning:
   * - null    → User is NOT logged in.
   * - number  → User is logged in, and the value is the SSO User ID.
   *
   * 1. If message.data is null, your app should:
   *      - Clear your session.
   *      - Redirect user to your login flow (if applicable).
   *
   * 2. If message.data is a number, your app should:
   *      - Compare it with your app’s current session user ID.
   *      - If they differ:
   *          → Clear your session and restart the login process.
   *
   * Note:
   * - removeListener() ensures this handler runs only once.
   */
  if (message.data === null) {
    // User is logged out in myzPAX
    // Clear session / redirect
  } else {
    // User is logged in
    // Validate SSO user ID against your session
    // If there is a mismatch, clear the session and restart the login flow.
  }

  removeListener(); // Unsubscribe after handling
});

// Request login status from myzPAX
sendZpaxMessage('login_status');

Use Cases

  • Pre-check before accessing protected content.
  • Load content based on the login status like showing marketing content when not logged in.

Related