function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chuck RamseyChuck Ramsey 

How do I implement logout in a custom User Profile Menu?

Salesforce uses a URL like "https://mycommunity/secur/logout.jsp?retUrl=https%3A%2F%2fmycommunityurl%2FCommunitiesLanding". If I use the force:navigateToUrl event with a similar URL, navigateToUrl sees the address as an absolute URL and always opens it in a new tab/window; the tab from which I click the Logout option in my User Profile Menu remains open and usable. Salesforce says that window.location won't work in Lightning and my experience supports that assertion. How does the User Profile Menu component supplied with Napili implement logout?

I know I've got the composition of the URL correct -- if I enter the URL in my browser I get the expected behavior:
  • If I'm logged in to the community as myself, I get logged out and returned to the login page.
  • If I'm logged in as an extranl (customer) user, I get sent back to the Contact page for that user.
Best Answer chosen by Chuck Ramsey
Chuck RamseyChuck Ramsey
Peeking at the JavaScript underlying Napili via my browser's development tools, I saw a call to $A.getEvt("markup://force:logout"). Trying to use the same code, I got an error just trying to save my component js controller. I tried using a documented interface to fetch the event:
var logout =  $A.get("e.force:logout");
logout.fire();
It worked in both of the situations called out in my question.  I cannot find documentation of this force: event anywhere; I'm sure the event has at least one paramter, perhaps more. I find this is in keeping with the documentation provided for creating a custom User Profile component -- practially nonexistent.