0

I have experience cloud login page which uses LWC and custom Apex controller with system site class to perform login operations.

After successful login we get a pageReference URL back from site class.

Apex code:

 ApexPages.PageReference pageRef = Site.login(username, password, startUrl);

        if(pageRef != null){
             return pageRef.getUrl();
        }

LWC JS:

  import doLogin from '@salesforce/apex/APP_LoginController.doLogin';

  doLogin({ username: this.username, password: this.password })
        .then(result => {

        

Below just refreshes page and sets it back to login page

window.open(result, '_self');

       

opens new tab and keeps login tab as is

this[NavigationMixin.Navigate]({
                type: 'comm__namedPage',
                attributes: {
                    name: 'Home'
                }
            });

        

keeps user on login page only

this[NavigationMixin.Navigate]({
                type: 'standard__webPage',
                attributes: {
                    url: `${basePath}/redeemcredits/`
                }
            },
            true 
          );

        })

Once the user is logged in, how do I redirect the user to the experience cloud Home page in the same tab?

3
  • 1
    What's the question? Expected behavior? Actual behavior?
    – sfdcfox
    Commented Jan 5, 2023 at 20:16
  • @sfdcfox Added the question at the end. Actual behavior is added in JS code. How do I redirect the user after they are logged in to to Home page? NavigatioMixin is not working in LWR site for some reason. Commented Jan 5, 2023 at 22:07
  • window.open(result, '_self'); should do the work. What is the value in result that you are getting, please debug and check it once.
    – Sarang
    Commented Jul 11, 2023 at 10:02

1 Answer 1

0

I think you need to use NavigationMixin.GenerateUrl. Then use window.open to open in the same window.


    this[NavigationMixin.GenerateUrl]({
        type: 'comm__namedPage',
                    attributes: {
                        name: 'Home'
                    }
    }).then(url => {
        window.open(url, "_self"); // this will replace the URL.
    });

1
  • I tried all different navigationMixin types including the above, it stays on the same page and refreshes the page but doesn't login. Commented Jan 6, 2023 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .