Is it possible to display toast message notification only once when user login to system on a home page?

I don't want toast message appear every time if I navigate to home page multiple time?

Wanted to know if its possible in LWC or AURA?


Yes, we can achieve this. We have to do these steps:

  1. Create a LWC/Aura component that can show toast message.
  2. The Aura component will use localStorage to track whether it's first time if yes then we will show the toast and update in localStorage.
  3. And if it's not first time then we simply skip the toast message.
  4. This component will not have any UI elements.
  5. Now drop the component on the home page using edit page.
  6. Logout and login again and you should see toast when you visit the page first time.

Here is the sample code of AURA:

var isFirstView = localStorage.getItem('isFirstView') || '';
if (isFirstView !== 'Yes') {
    /* Show message to use as this is first view. */
    localStorage.setItem('isFirstView', 'Yes');

In my requirement I wanted to use local storage.

  • Does LWC use localstorage? Is there a sample for AURA or LWC that you can provide?
    – SFBeginner
    Oct 29 '20 at 12:52
  • developer.mozilla.org/en-US/docs/Web/API/Window/localStorage give it a try and share with others. Oct 29 '20 at 13:09
  • where can I use Local storage within JS or cmp file? Sorry I am new in Lightning, did not work much.
    – SFBeginner
    Oct 29 '20 at 13:20
  • I tried but it does not show the message once Logout and Login again.
    – SFBeginner
    Oct 29 '20 at 13:32
  • with the help of sessionStorage it can be done. Tried and it works. Thanks for the help
    – SFBeginner
    Oct 29 '20 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.