We have a custom LWC Login page under an experience builder site, which uses a custom apex controller and site.login
method to authenticate the user.
Apex Authentication code :
ApexPages.PageReference pageRef = Site.login(username, password, startUrl);
if(pageRef != null){
system.debug(pageRef);
return pageRef.getUrl();
}
After the user is authenticated, pageRef is sent back to LWC as string with session.
In LWC, I need to navigate user to home page after logging in, but navigationMixin is opening the URL is new tab instead of refreshing current page.
LWC Code to Navigate:
navigateToWebPage(url) {
this[NavigationMixin.Navigate]({
"type": "standard__webPage",
"attributes": {
"url": url
}
});
}
I also tried window.location.href
but that does not navigate the user at all.
How do I redirect the user to the home page after they are authenticated with session in Experience cloud LWC?