[FIX] Redirect user to SetUsernameView (#1728)
Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
c36a0363fc
commit
9220f9e9e4
|
@ -118,7 +118,7 @@ const start = function* start({ root }) {
|
||||||
if (root === 'inside') {
|
if (root === 'inside') {
|
||||||
yield Navigation.navigate('InsideStack');
|
yield Navigation.navigate('InsideStack');
|
||||||
} else if (root === 'setUsername') {
|
} else if (root === 'setUsername') {
|
||||||
yield Navigation.navigate('SetUsernameView');
|
yield Navigation.navigate('SetUsernameStack');
|
||||||
} else if (root === 'outside') {
|
} else if (root === 'outside') {
|
||||||
yield Navigation.navigate('OutsideStack');
|
yield Navigation.navigate('OutsideStack');
|
||||||
} else if (root === 'loading') {
|
} else if (root === 'loading') {
|
||||||
|
|
|
@ -35,7 +35,13 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE
|
||||||
} else {
|
} else {
|
||||||
result = yield call(loginWithPasswordCall, credentials);
|
result = yield call(loginWithPasswordCall, credentials);
|
||||||
}
|
}
|
||||||
return yield put(loginSuccess(result));
|
if (!result.username) {
|
||||||
|
yield put(serverFinishAdd());
|
||||||
|
yield put(setUser(result));
|
||||||
|
yield put(appStart('setUsername'));
|
||||||
|
} else {
|
||||||
|
yield put(loginSuccess(result));
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (logoutOnError && (e.data && e.data.message && /you've been logged out by the server/i.test(e.data.message))) {
|
if (logoutOnError && (e.data && e.data.message && /you've been logged out by the server/i.test(e.data.message))) {
|
||||||
yield put(logout(true));
|
yield put(logout(true));
|
||||||
|
@ -117,9 +123,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
|
||||||
EventEmitter.emit('connected');
|
EventEmitter.emit('connected');
|
||||||
|
|
||||||
let currentRoot;
|
let currentRoot;
|
||||||
if (!user.username) {
|
if (adding) {
|
||||||
yield put(appStart('setUsername'));
|
|
||||||
} else if (adding) {
|
|
||||||
yield put(serverFinishAdd());
|
yield put(serverFinishAdd());
|
||||||
yield put(appStart('inside'));
|
yield put(appStart('inside'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -193,7 +197,6 @@ const root = function* root() {
|
||||||
while (true) {
|
while (true) {
|
||||||
const params = yield take(types.LOGIN.SUCCESS);
|
const params = yield take(types.LOGIN.SUCCESS);
|
||||||
const loginSuccessTask = yield fork(handleLoginSuccess, params);
|
const loginSuccessTask = yield fork(handleLoginSuccess, params);
|
||||||
// yield take(types.SERVER.SELECT_REQUEST);
|
|
||||||
yield race({
|
yield race({
|
||||||
selectRequest: take(types.SERVER.SELECT_REQUEST),
|
selectRequest: take(types.SERVER.SELECT_REQUEST),
|
||||||
timeout: delay(2000)
|
timeout: delay(2000)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import {
|
import { Keyboard, Text, ScrollView } from 'react-native';
|
||||||
Keyboard, Text, ScrollView, Alert
|
|
||||||
} from 'react-native';
|
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { SafeAreaView } from 'react-navigation';
|
import { SafeAreaView } from 'react-navigation';
|
||||||
import RNPickerSelect from 'react-native-picker-select';
|
import RNPickerSelect from 'react-native-picker-select';
|
||||||
|
@ -24,6 +22,7 @@ import { withTheme } from '../theme';
|
||||||
import { themes } from '../constants/colors';
|
import { themes } from '../constants/colors';
|
||||||
import { themedHeader } from '../utils/navigation';
|
import { themedHeader } from '../utils/navigation';
|
||||||
import { isTablet } from '../utils/deviceInfo';
|
import { isTablet } from '../utils/deviceInfo';
|
||||||
|
import { showErrorAlert } from '../utils/info';
|
||||||
|
|
||||||
const shouldUpdateState = ['name', 'email', 'password', 'username', 'saving'];
|
const shouldUpdateState = ['name', 'email', 'password', 'username', 'saving'];
|
||||||
|
|
||||||
|
@ -129,12 +128,15 @@ class RegisterView extends React.Component {
|
||||||
|
|
||||||
if (Accounts_EmailVerification) {
|
if (Accounts_EmailVerification) {
|
||||||
await navigation.goBack();
|
await navigation.goBack();
|
||||||
Alert.alert(I18n.t('Verify_email_title'), I18n.t('Verify_email_desc'));
|
showErrorAlert(I18n.t('Verify_email_desc'), I18n.t('Verify_email_title'));
|
||||||
} else {
|
} else {
|
||||||
await loginRequest({ user: email, password });
|
await loginRequest({ user: email, password });
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Alert.alert(I18n.t('Oops'), e.data.error);
|
if (e.data && e.data.errorType === 'username-invalid') {
|
||||||
|
return loginRequest({ user: email, password });
|
||||||
|
}
|
||||||
|
showErrorAlert(e.data.error, I18n.t('Oops'));
|
||||||
}
|
}
|
||||||
this.setState({ saving: false });
|
this.setState({ saving: false });
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,12 @@ import scrollPersistTaps from '../utils/scrollPersistTaps';
|
||||||
import I18n from '../i18n';
|
import I18n from '../i18n';
|
||||||
import RocketChat from '../lib/rocketchat';
|
import RocketChat from '../lib/rocketchat';
|
||||||
import StatusBar from '../containers/StatusBar';
|
import StatusBar from '../containers/StatusBar';
|
||||||
import log from '../utils/log';
|
|
||||||
import { themedHeader } from '../utils/navigation';
|
import { themedHeader } from '../utils/navigation';
|
||||||
import { withTheme } from '../theme';
|
import { withTheme } from '../theme';
|
||||||
import { themes } from '../constants/colors';
|
import { themes } from '../constants/colors';
|
||||||
import { isTablet } from '../utils/deviceInfo';
|
import { isTablet } from '../utils/deviceInfo';
|
||||||
import { getUserSelector } from '../selectors/login';
|
import { getUserSelector } from '../selectors/login';
|
||||||
|
import { showErrorAlert } from '../utils/info';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
loginTitle: {
|
loginTitle: {
|
||||||
|
@ -96,7 +96,7 @@ class SetUsernameView extends React.Component {
|
||||||
await RocketChat.setUsername(username);
|
await RocketChat.setUsername(username);
|
||||||
await loginRequest({ resume: token });
|
await loginRequest({ resume: token });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e);
|
showErrorAlert(e.message, I18n.t('Oops'));
|
||||||
}
|
}
|
||||||
this.setState({ saving: false });
|
this.setState({ saving: false });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue