2

I have a custom portal/community registration page created using LWC, which uses:

Site.createExternalUser(...);

To create the user.

Once the user is created, I want to automatically log them into the portal and redirect them to an internal page.

I've tried using:

Site.login(username, password, null);

And returning true back to the LWC and doing a client-side redirect to the page, but it did not work.

Questions

  1. What is wrong with the above approach?
  2. How can I fix it?
1
  • LWC actually lacks this feature. We built a similar code with passwordless login first with LWC and then with Aura but there as well we had issues that a user was not able to post chatter comments. So we ended up using VF page inside Aura for form submission. – manjit5190 Apr 30 '20 at 17:50
0

I got it working like this:

@AuraEnabled
public static String createAccount(...) {

   // create account and user etc...

   ApexPages.PageReference pageRef = Site.login(...);

   return pageRef.getUrl();
}

Then on the client-side:

createAccount(...)
    .then(data => {
        if (data) {
            window.location.href = data;
        } 
    }).catch(error => {
        console.error(error);
    });

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.