From 339ff1ae8fd3d746b151fb9341e8913ec025a0b5 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Thu, 25 Jul 2019 08:12:32 -0400 Subject: [PATCH] Fix assigning credentials during app init (#3034) * Fix assigning credentials during app init * remove setAppCredentials in entry screen --- app/app.js | 5 ++++- app/screens/entry/entry.js | 43 +++++++++----------------------------- app/screens/entry/index.js | 2 -- 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/app/app.js b/app/app.js index 1011b164d..5cca28ebe 100644 --- a/app/app.js +++ b/app/app.js @@ -6,6 +6,7 @@ import {Linking, NativeModules, Platform, Text} from 'react-native'; import AsyncStorage from '@react-native-community/async-storage'; import {setGenericPassword, getGenericPassword, resetGenericPassword} from 'react-native-keychain'; +import {setDeviceToken} from 'mattermost-redux/actions/general'; import {loadMe} from 'mattermost-redux/actions/users'; import {Client4} from 'mattermost-redux/client'; import EventEmitter from 'mattermost-redux/utils/event_emitter'; @@ -127,10 +128,12 @@ export default class App { // if for any case the url and the token aren't valid proceed with re-hydration if (url && url !== 'undefined' && token && token !== 'undefined') { - this.deviceToken = deviceToken; + const {dispatch} = store; + this.currentUserId = currentUserId; this.token = token; this.url = url; + dispatch(setDeviceToken(deviceToken)); Client4.setUrl(url); Client4.setToken(token); await setCSRFFromCookie(url); diff --git a/app/screens/entry/entry.js b/app/screens/entry/entry.js index 1a6fa9073..5485ba404 100644 --- a/app/screens/entry/entry.js +++ b/app/screens/entry/entry.js @@ -21,7 +21,6 @@ import { } from 'app/mattermost'; import {ViewTypes} from 'app/constants'; import PushNotifications from 'app/push_notifications'; -import {stripTrailingSlashes} from 'app/utils/url'; import {wrapWithContextProvider} from 'app/utils/wrap_context_provider'; import ChannelLoader from 'app/components/channel_loader'; @@ -64,7 +63,6 @@ export default class Entry extends PureComponent { initializeModules: PropTypes.func, actions: PropTypes.shape({ autoUpdateTimezone: PropTypes.func.isRequired, - setDeviceToken: PropTypes.func.isRequired, }).isRequired, }; @@ -128,7 +126,16 @@ export default class Entry extends PureComponent { autoUpdateTimezone(deviceTimezone); } - this.setAppCredentials(); + const {currentUserId} = state.entities.users; + + if (app.waitForRehydration) { + app.waitForRehydration = false; + } + + if (currentUserId) { + Client4.setUserId(currentUserId); + } + this.setStartupThemes(); this.handleNotification(); this.loadSystemEmojis(); @@ -147,36 +154,6 @@ export default class Entry extends PureComponent { configureNotifications(); }; - setAppCredentials = () => { - const { - actions: { - setDeviceToken, - }, - } = this.props; - const {getState} = store; - const state = getState(); - - const {credentials} = state.entities.general; - const {currentUserId} = state.entities.users; - - if (app.deviceToken) { - setDeviceToken(app.deviceToken); - } - - if (credentials.token && credentials.url) { - Client4.setToken(credentials.token); - Client4.setUrl(stripTrailingSlashes(credentials.url)); - } else if (app.waitForRehydration) { - app.waitForRehydration = false; - } - - if (currentUserId) { - Client4.setUserId(currentUserId); - } - - app.setAppCredentials(app.deviceToken, currentUserId, credentials.token, credentials.url); - }; - setStartupThemes = () => { const {theme} = this.props; if (app.toolbarBackground === theme.sidebarHeaderBg) { diff --git a/app/screens/entry/index.js b/app/screens/entry/index.js index 22bebdae8..6941539f1 100644 --- a/app/screens/entry/index.js +++ b/app/screens/entry/index.js @@ -3,7 +3,6 @@ import {bindActionCreators} from 'redux'; import {connect} from 'react-redux'; -import {setDeviceToken} from 'mattermost-redux/actions/general'; import {autoUpdateTimezone} from 'mattermost-redux/actions/timezone'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; import {isTimezoneEnabled} from 'mattermost-redux/selectors/entities/timezone'; @@ -31,7 +30,6 @@ function mapDispatchToProps(dispatch) { return { actions: bindActionCreators({ autoUpdateTimezone, - setDeviceToken, }, dispatch), }; }