3

I'm developing a Community and I have a custom Login Aura controller. To log in the user I use the standard Site.login() method that returns a pageReference, that then is passed to aura.redirect()

Login Controller:

ApexPages.PageReference lgn = Site.login(username, password, startUrl);
if(!Test.isRunningTest())aura.redirect(lgn);

aura.redirect() won't navigate to Home and it doesn't throw an error either.


I've also tried to navigate to Home using NavigationMixin.Navigate but it doesn't work either.

I send a response from my controller to my LWC and there in the component I try to navigate from the login page to Home using the following code, but it just won't work

LWC:

this[NavigationMixin.Navigate]({
        type : 'standard__namedPage',
        attributes : {
            pageName : 'home'
        },
});

Any ideas on how to log in the user and then take the user from the community login page to Home using LWC?

  • Try wrapping your login lwc component in a standard Aura one... then all your UI can be lwc, but hopefully the call to the back end will go through the standard Aura framework. – Caspar Harmer Jun 9 at 19:36
3

Well after doing some research I found out that apparently and according to René Winkelmeyer (Salesforce Principal Developer Evangelist) in this GitHub Issue:

lightning-navigation is currently not a supported experience for Communities.

3

In Summer '19, Salesforce enhanced the support of lightning-navigation in Community with comm__namedPage (instead of standard__namedPage), pageReferences and state.

https://releasenotes.docs.salesforce.com/en-us/summer19/release-notes/rn_lwc_modules.htm

export default class myClass extends NavigationMixin(LightningElement) {
 //...

 goToFAQCategoryMesInstallations() {
  this[NavigationMixin.Navigate]({
   type: 'comm__namedPage',
   attributes: {
    pageName: 'faq',
   },
   state: {
    'category': 'Mes_installations'
   }
  });
 }
}

this will redirect you to 'yourCommunity'/s/faq?category=Mes_installations

0

You can pass startUrl with portal name where you want to redirect. Like if portal url is https://****-****.cs77.force.com/customerportal then you can pass /customerportal/s in starturl. This will redirect you to home page after validation.

if(site.isValidUsername(username)){
   //startUrl -- put portal name in this variable 
   ApexPages.PageReference lgn = Site.login(username, password, startUrl);
   aura.redirect(lgn);
   return null;                
 }

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.