diff --git a/app/actions/login.ts b/app/actions/login.ts index 17174145c..5d27cdfe6 100644 --- a/app/actions/login.ts +++ b/app/actions/login.ts @@ -13,6 +13,7 @@ interface ILoginRequest extends Action { credentials: any; logoutOnError?: boolean; isFromWebView?: boolean; + registerCustomFields?: any; } interface ILoginSuccess extends Action { @@ -56,13 +57,15 @@ export type TActionsLogin = ILoginRequest & export function loginRequest( credentials: Partial, logoutOnError?: boolean, - isFromWebView?: boolean + isFromWebView?: boolean, + registerCustomFields?: any ): ILoginRequest { return { type: types.LOGIN.REQUEST, credentials, logoutOnError, - isFromWebView + isFromWebView, + registerCustomFields }; } diff --git a/app/sagas/login.js b/app/sagas/login.js index 1a9318806..af2ad9b03 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -42,7 +42,12 @@ const loginWithPasswordCall = args => Services.loginWithPassword(args); const loginCall = (credentials, isFromWebView) => Services.login(credentials, isFromWebView); 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); try { let result; @@ -78,6 +83,10 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE } }); yield put(loginSuccess(result)); + if (registerCustomFields) { + const updatedUser = yield call(Services.saveUserProfile, {}, { ...registerCustomFields }); + yield put(setUser({ ...result, ...updatedUser.user })); + } } } catch (e) { if (e?.data?.message && /you've been logged out by the server/i.test(e.data.message)) { diff --git a/app/views/RegisterView.tsx b/app/views/RegisterView.tsx index 982a116e1..039cb277a 100644 --- a/app/views/RegisterView.tsx +++ b/app/views/RegisterView.tsx @@ -127,22 +127,22 @@ class RegisterView extends React.Component { const { dispatch, Accounts_EmailVerification, navigation, Accounts_ManuallyApproveNewUsers } = this.props; try { - await Services.register({ + const user = await Services.register({ name, email, pass: password, - username, - ...customFields + username }); - - if (Accounts_EmailVerification) { - await navigation.goBack(); - showErrorAlert(I18n.t('Verify_email_desc'), I18n.t('Registration_Succeeded')); - } else if (Accounts_ManuallyApproveNewUsers) { - await navigation.goBack(); - showErrorAlert(I18n.t('Wait_activation_warning'), I18n.t('Registration_Succeeded')); - } else { - dispatch(loginRequest({ user: email, password })); + if (user.success) { + if (Accounts_EmailVerification) { + await navigation.goBack(); + showErrorAlert(I18n.t('Verify_email_desc'), I18n.t('Registration_Succeeded')); + } else if (Accounts_ManuallyApproveNewUsers) { + await navigation.goBack(); + showErrorAlert(I18n.t('Wait_activation_warning'), I18n.t('Registration_Succeeded')); + } else { + dispatch(loginRequest({ user: email, password }, false, false, customFields)); + } } } catch (e: any) { if (e.data?.errorType === 'username-invalid') {