Custom Logout Button on Lightning Component in Community

Screen Shot 2016-02-24 at 11.30.11 AM

If you want to create your own logout button for a Community Lightning Component, you can use the window.location.replace() javascript function.

The button component (note: this example is the button only, you would typically include this in a Notification):

<aura:component implements="forceCommunity:availableForAllPageTypes" 
 access="global">
    <ui:button label="Logout" press="{!c.logout}"/>
</aura:component>

And in your controller, you can redirect the user to the logout page:

({
    logout : function(component, event, helper) {
        window.location.replace("https://YourCommunityDomain/servlet/networks/switch?startURL=%2Fsecur%2Flogout.jsp");
    }
})

Just replace “YourCommunityDomain” with whatever the base URL is for your community.  Typically something like “MyDomain.na10.force.com”.  This will redirect the user to the standard logout page for your community.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s