Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/actions/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ILoginRequest extends Action {
credentials: any;
logoutOnError?: boolean;
isFromWebView?: boolean;
registerCustomFields?: any;
}

interface ILoginSuccess extends Action {
Expand Down Expand Up @@ -56,13 +57,15 @@ export type TActionsLogin = ILoginRequest &
export function loginRequest(
credentials: Partial<ICredentials>,
logoutOnError?: boolean,
isFromWebView?: boolean
isFromWebView?: boolean,
registerCustomFields?: any
): ILoginRequest {
return {
type: types.LOGIN.REQUEST,
credentials,
logoutOnError,
isFromWebView
isFromWebView,
registerCustomFields
};
}

Expand Down
11 changes: 10 additions & 1 deletion app/sagas/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
24 changes: 12 additions & 12 deletions app/views/RegisterView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,22 @@ class RegisterView extends React.Component<IProps, any> {
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') {
Expand Down