+ Start a Discussion

Clear localStorage from controller when user logs out of from salesforce.


I want to clear the "localStorage" which is set in JS controller when user logs out of salesforce. It should avaialble only till user is logged in salesforce. 

<aura:component implements="flexipage:availableForAllPageTypes" access="global" controller="PopupMessageController">  
    <aura:attribute name="ListOfMessage" type="Popup_Message__c[]" description="displayes list of messages"/>
    <aura:handler name='init' action="{!c.doInit}" value="{!this}" /> 
    <aura:attribute name="isOpen" type="boolean" default="False" />
    <aura:if isTrue="{!and(v.isOpen,v.ListOfMessage != null)}">          
    <div class="slds-backdrop" aura:id="Modalbackdrop"></div>         
        <div role="dialog" tabindex="-1" aria-labelledby="header43" class='pop-up slds-modal' aura:id="popupDiv1">
            <div class="slds-modal__container">               
              <div class="slds-modal__pinner">                      
                    <div class="message">	
                        <!-- <p>Sudhir First </p> -->                         
      					<aura:iteration items="{!v.ListOfMessage}" var="msg">
                             <li> {!msg.Message_Text__c} </li> 
                    <div class="slds-form-element" >
                     <!--   <lightning:button class="slds-button slds-button_neutral" variant="success" label="OK" title="OK" onclick="{!c.close }" /> -->                       
                          <button  onclick="{!c.close }">OK</button>                     
        <aura:set attribute="else">

    doInit : function(component, event, helper) {
        var action = component.get('c.fetchMessage',true);
        action.setCallback(this, function(response) {
        //store state of response
        var state = response.getState();
        if (state === "SUCCESS") {
         //set response value in ListOfMessage attribute on component.
         component.set('v.ListOfMessage', response.getReturnValue());
        var temperorySession = localStorage.getItem('tempSession');
        if(temperorySession == '1')
            component.set("v.isOpen", false); //This should be set to false to testing set to true
            component.set("v.isOpen", true);
            var cmpTarget1 = component.find('popupDiv1');
            var cmpBack1 = component.find('Modalbackdrop1');
            $A.util.addClass(cmpTarget1, 'slds-fade-in-open');
            $A.util.addClass(cmpBack1, 'slds-backdrop--open');
        localStorage.setItem('tempSession', '1'); 
    close: function(component, event, helper) {
        component.set("v.isOpen", false);

Please suggest me how to implement.