This message is sent from the embedded application to query the user's authentication status. The login_status 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
type messageType = 'login_status';Payload
None
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
- Guard protected views with authentication checks.
- Trigger auth flow dynamically.
Related
login_status— The corresponding response from myzPAX.sendZpaxMessage— Function to send messages to myzPAX.addZpaxMessageListener— Function to listen messages from myzPAX.