[FIX] When creating a new user, "Custom Fields" are breaking functionality (#4501)
This commit is contained in:
parent
fa971deabf
commit
92b590431d
|
@ -13,6 +13,7 @@ interface ILoginRequest extends Action {
|
||||||
credentials: any;
|
credentials: any;
|
||||||
logoutOnError?: boolean;
|
logoutOnError?: boolean;
|
||||||
isFromWebView?: boolean;
|
isFromWebView?: boolean;
|
||||||
|
registerCustomFields?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ILoginSuccess extends Action {
|
interface ILoginSuccess extends Action {
|
||||||
|
@ -56,13 +57,15 @@ export type TActionsLogin = ILoginRequest &
|
||||||
export function loginRequest(
|
export function loginRequest(
|
||||||
credentials: Partial<ICredentials>,
|
credentials: Partial<ICredentials>,
|
||||||
logoutOnError?: boolean,
|
logoutOnError?: boolean,
|
||||||
isFromWebView?: boolean
|
isFromWebView?: boolean,
|
||||||
|
registerCustomFields?: any
|
||||||
): ILoginRequest {
|
): ILoginRequest {
|
||||||
return {
|
return {
|
||||||
type: types.LOGIN.REQUEST,
|
type: types.LOGIN.REQUEST,
|
||||||
credentials,
|
credentials,
|
||||||
logoutOnError,
|
logoutOnError,
|
||||||
isFromWebView
|
isFromWebView,
|
||||||
|
registerCustomFields
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,12 @@ const loginWithPasswordCall = args => Services.loginWithPassword(args);
|
||||||
const loginCall = (credentials, isFromWebView) => Services.login(credentials, isFromWebView);
|
const loginCall = (credentials, isFromWebView) => Services.login(credentials, isFromWebView);
|
||||||
const logoutCall = args => logout(args);
|
const logoutCall = args => logout(args);
|
||||||
|
|
||||||
const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnError = false, isFromWebView = false }) {
|
const handleLoginRequest = function* handleLoginRequest({
|
||||||
|
credentials,
|
||||||
|
logoutOnError = false,
|
||||||
|
isFromWebView = false,
|
||||||
|
registerCustomFields
|
||||||
|
}) {
|
||||||
logEvent(events.LOGIN_DEFAULT_LOGIN);
|
logEvent(events.LOGIN_DEFAULT_LOGIN);
|
||||||
try {
|
try {
|
||||||
let result;
|
let result;
|
||||||
|
@ -78,6 +83,10 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
yield put(loginSuccess(result));
|
yield put(loginSuccess(result));
|
||||||
|
if (registerCustomFields) {
|
||||||
|
const updatedUser = yield call(Services.saveUserProfile, {}, { ...registerCustomFields });
|
||||||
|
yield put(setUser({ ...result, ...updatedUser.user }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e?.data?.message && /you've been logged out by the server/i.test(e.data.message)) {
|
if (e?.data?.message && /you've been logged out by the server/i.test(e.data.message)) {
|
||||||
|
|
|
@ -127,22 +127,22 @@ class RegisterView extends React.Component<IProps, any> {
|
||||||
const { dispatch, Accounts_EmailVerification, navigation, Accounts_ManuallyApproveNewUsers } = this.props;
|
const { dispatch, Accounts_EmailVerification, navigation, Accounts_ManuallyApproveNewUsers } = this.props;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Services.register({
|
const user = await Services.register({
|
||||||
name,
|
name,
|
||||||
email,
|
email,
|
||||||
pass: password,
|
pass: password,
|
||||||
username,
|
username
|
||||||
...customFields
|
|
||||||
});
|
});
|
||||||
|
if (user.success) {
|
||||||
if (Accounts_EmailVerification) {
|
if (Accounts_EmailVerification) {
|
||||||
await navigation.goBack();
|
await navigation.goBack();
|
||||||
showErrorAlert(I18n.t('Verify_email_desc'), I18n.t('Registration_Succeeded'));
|
showErrorAlert(I18n.t('Verify_email_desc'), I18n.t('Registration_Succeeded'));
|
||||||
} else if (Accounts_ManuallyApproveNewUsers) {
|
} else if (Accounts_ManuallyApproveNewUsers) {
|
||||||
await navigation.goBack();
|
await navigation.goBack();
|
||||||
showErrorAlert(I18n.t('Wait_activation_warning'), I18n.t('Registration_Succeeded'));
|
showErrorAlert(I18n.t('Wait_activation_warning'), I18n.t('Registration_Succeeded'));
|
||||||
} else {
|
} else {
|
||||||
dispatch(loginRequest({ user: email, password }));
|
dispatch(loginRequest({ user: email, password }, false, false, customFields));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e.data?.errorType === 'username-invalid') {
|
if (e.data?.errorType === 'username-invalid') {
|
||||||
|
|
Loading…
Reference in New Issue