You need to sign in to do that
Don't have an account?
GMASJ
Clear localStorage from controller when user logs out of from salesforce.
Hi,
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.
Component
Controller
Please suggest me how to implement.
Thanks
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.
Component
<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> --> <ul> <aura:iteration items="{!v.ListOfMessage}" var="msg"> <li> {!msg.Message_Text__c} </li> <br/> </aura:iteration> </ul> </div> <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> </div> </div> </div> </div> <aura:set attribute="else"> <div> </div> </aura:set> </aura:if> </aura:component>
Controller
({ 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()); } }); $A.enqueueAction(action); var temperorySession = localStorage.getItem('tempSession'); alert(temperorySession); if(temperorySession == '1') { component.set("v.isOpen", false); //This should be set to false to testing set to true } else { 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'); $A.enqueueAction(action); } localStorage.setItem('tempSession', '1'); }, close: function(component, event, helper) { component.set("v.isOpen", false); //localStorage.clear(); } })
Please suggest me how to implement.
Thanks