You need to sign in to do that
Don't have an account?
RC 14
Custom self register component doesn't login users
After Winter 21 release updates, my custom self register component for lightining community stopped working properly. User record is successfully created, but they are not logged in after registration. Here is the method for self registration in the apex controller:
public static String selfRegister(String firstname ,String lastname, String email, String password, String confirmPassword, String accountId, String regConfirmUrl, String extraFields, String startUrl, Boolean includePassword) { Savepoint sp = null; try { sp = Database.setSavepoint(); if (lastname == null || String.isEmpty(lastname)) { return Label.Site.lastname_is_required; } if (email == null || String.isEmpty(email)) { return Label.Site.email_is_required; } User u = new User(); u.Username = email; u.put('Email',email); u.FirstName = firstname; u.LastName = lastname; String networkId = Network.getNetworkId(); // If using site to host the community the user should not hit s1 after logging in from mobile. if(networkId != null && siteAsContainerEnabled(Network.getLoginUrl(networkId))) { u.put('UserPreferencesHideS1BrowserUI',true); } String nickname = ((firstname != null && firstname.length() > 0) ? firstname.substring(0,1) : '' ) + lastname.substring(0,1); nickname += String.valueOf(Crypto.getRandomInteger()).substring(1,7); u.put('CommunityNickname', nickname); if (extraFields != null) { List<Object> extraFieldsList = (List<Object>) JSON.deserializeUntyped(extraFields); for (Object thisFieldObject : extraFieldsList) { Map<String,Object> thisField = (Map<String,Object>) thisFieldObject; Schema.SObjectField sof = Schema.SObjectType.User.fields.getMap().get((String) thisField.get('fieldPath')); u.put(sof, thisField.get('value')); } } if (includePassword) { if (!isValidPassword(password, confirmPassword)) { return Label.site.passwords_dont_match; } validatePassword(u, password, confirmPassword); } else { password = null; } // lastName is a required field on user, but if it isn't specified, we'll default it to the username String userId = Site.createPortalUser(u, accountId, password); // create a fake userId for test. if (Test.isRunningTest()) { userId = 'fakeUserId'; } if (userId != null) { if (password != null && password.length() > 1) { ApexPages.PageReference lgn = Site.login(email, password, startUrl); if(!Test.isRunningTest()) { aura.redirect(lgn); } } else { ApexPages.PageReference confirmRef = new PageReference(regConfirmUrl); if(!Test.isRunningTest()) { aura.redirect(confirmRef); } } } return null; } catch (Exception ex) { Database.rollback(sp); System.debug(ex.getCause() + ' at ' + ex.getLineNumber() + ' Stack Trace: ' + ex.getStackTraceString()); return ex.getMessage(); } }
If yes you can compare the logs and Did you notice any issue from your end?