11

I'm looking at one of the custom login controllers for communities and noticed this:

@AuraEnabled
public static String login(String username, String password, String startUrl) {

    try{
        ApexPages.PageReference lgn = Site.login(username, password, startUrl);
        aura.redirect(lgn);
        return null;
    }
    catch (Exception ex) {
        system.debug('error message ' + ex.getMessage());
        return ex.getMessage();  
    }
}

Basically, the user will enter in a username and password, and after they click "login" they will be redirected to the start url. Is there any documentation around aura.redirect?

5

No documentation can be found in Salesforce but it just works. The other issue I found is that for some reason test classes don't work well with them. Hence I include code like

if(!Test.isRunningTest()) { aura.redirect(lgn); }

so that I doesn't affect the test class and code coverage.

0

Ultimately moved away from aura.redirect and used window.location.href to sent the new endpoint. Once the apex controller finished, the callback function in the component redirected the user accordingly.

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.