Login Status Change
An event that keeps an eye if customer has logged in or not
Description
The onLoginStatusChanged event triggers whenever a customer logs in or logs out of their account.
It helps you personalize the experience — for example, showing customer specific data, showing loyalty points, or updating navigation options.
Function Signature
VajroSDK.listeners.onLoginStatusChanged(() => {
// Write your logic
});| Parameter | Type | Required | Description |
|---|---|---|---|
| Nil | Nil | Nil | This listener does not require any parameter. |
Example Usage
VajroSDK.listeners.onLoginStatusChanged(() => {
if (VajroSDK.variables.customer != null) {
const customerName = VajroSDK.variables.customer.firstName;
console.log(`Welcome back, ${customerName}!`);
} else {
console.log("Goodbye! See you next time.");
}
});Best Practices
- Use with VajroSDK.variables.customer: Retrieve the full customer object when user logs in.
- Re-render personalized sections: Refresh loyalty, wishlist, or order history.
- Clear sensitive data: On logout, reset local storage or cached user data.
Caveats
- Immediate firing: This event fires instantly when login state changes, not on page load.
- No replay: If you subscribe after login, you won’t receive the last known state.
Updated about 1 month ago