> ## Documentation Index
> Fetch the complete documentation index at: https://docs.myzpax.com/llms.txt
> Use this file to discover all available pages before exploring further.

# login_status

This message is sent from the embedded application to query the user's authentication status. The [`login_status`](https://docs.myzpax.com/reference/login_status-1)  response must be listened to prior to issuing the request. If the user is authenticated, the response returns the `userId`; otherwise, it returns `null`.

## Message Type

```typescript
type messageType = 'login_status';
```

## Payload

None

## Example

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

```typescript
// 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

* Guard protected views with authentication checks.
* Trigger auth flow dynamically.

## Related

* [`login_status`](../response-message/login_status.md) — The corresponding response from myzPAX.
* [`sendZpaxMessage`](https://docs.z-pax.com/reference/sendzpaxmessage) — Function to send messages to myzPAX.
* [`addZpaxMessageListener`](https://docs.z-pax.com/reference/addzpaxmessagelistener) — Function to listen messages from myzPAX.