17

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?

2

2 Answers 2

8

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.

2

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.

You must log in to answer this question.

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