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
});
ParameterTypeRequiredDescription
NilNilNilThis 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

  1. Use with VajroSDK.variables.customer: Retrieve the full customer object when user logs in.
  2. Re-render personalized sections: Refresh loyalty, wishlist, or order history.
  3. Clear sensitive data: On logout, reset local storage or cached user data.

Caveats

  1. Immediate firing: This event fires instantly when login state changes, not on page load.
  2. No replay: If you subscribe after login, you won’t receive the last known state.