diff --git a/app/actions/views/login.js b/app/actions/views/login.js index 4bc2d3100..e1c424d97 100644 --- a/app/actions/views/login.js +++ b/app/actions/views/login.js @@ -25,21 +25,31 @@ export function handlePasswordChanged(password) { export function handleSuccessfulLogin() { return async (dispatch, getState) => { - const {currentUserId} = getState().entities.users; - const token = Client4.getToken(); - dispatch({ type: GeneralTypes.RECEIVED_APP_CREDENTIALS, data: { url: Client4.getUrl(), - token + token: Client4.getToken() } - }); + }, getState); - const session = await Client4.getSessions(currentUserId, token); - if (Array.isArray(session) && session[0]) { - const s = session[0]; - return s.expires_at; + return true; + }; +} + +export function getSession() { + return async (dispatch, getState) => { + const state = getState(); + const {currentUserId} = state.entities.users; + const {credentials} = state.entities.general; + const token = credentials && credentials.token; + + if (currentUserId && token) { + const session = await Client4.getSessions(currentUserId, token); + if (Array.isArray(session) && session[0]) { + const s = session[0]; + return s.expires_at; + } } return false; @@ -49,5 +59,6 @@ export function handleSuccessfulLogin() { export default { handleLoginIdChanged, handlePasswordChanged, - handleSuccessfulLogin + handleSuccessfulLogin, + getSession }; diff --git a/app/screens/login/login.js b/app/screens/login/login.js index 39bbf73c5..1dd537733 100644 --- a/app/screens/login/login.js +++ b/app/screens/login/login.js @@ -37,6 +37,7 @@ class Login extends PureComponent { handleLoginIdChanged: PropTypes.func.isRequired, handlePasswordChanged: PropTypes.func.isRequired, handleSuccessfulLogin: PropTypes.func.isRequired, + getSession: PropTypes.func.isRequired, checkMfa: PropTypes.func.isRequired, login: PropTypes.func.isRequired }).isRequired, @@ -64,7 +65,7 @@ class Login extends PureComponent { componentWillReceiveProps(nextProps) { if (this.props.loginRequest.status === RequestStatus.STARTED && nextProps.loginRequest.status === RequestStatus.SUCCESS) { - this.props.actions.handleSuccessfulLogin().then(this.goToLoadTeam); + this.props.actions.handleSuccessfulLogin().then(this.props.actions.getSession).then(this.goToLoadTeam); } } @@ -193,8 +194,9 @@ class Login extends PureComponent { }; signIn = () => { - if (this.props.loginRequest.status !== RequestStatus.STARTED) { - this.props.actions.login(this.props.loginId, this.props.password); + const {actions, loginId, loginRequest, password} = this.props; + if (loginRequest.status !== RequestStatus.STARTED) { + actions.login(loginId.toLowerCase(), password); } }; diff --git a/app/screens/sso/index.js b/app/screens/sso/index.js index 3ffb3dbd4..ee460bbfc 100644 --- a/app/screens/sso/index.js +++ b/app/screens/sso/index.js @@ -4,7 +4,7 @@ import {bindActionCreators} from 'redux'; import {connect} from 'react-redux'; -import {handleSuccessfulLogin} from 'app/actions/views/login'; +import {getSession, handleSuccessfulLogin} from 'app/actions/views/login'; import {getTheme} from 'app/selectors/preferences'; import {setStoreFromLocalData} from 'mattermost-redux/actions/general'; @@ -22,6 +22,7 @@ function mapStateToProps(state, ownProps) { function mapDispatchToProps(dispatch) { return { actions: bindActionCreators({ + getSession, handleSuccessfulLogin, setStoreFromLocalData }, dispatch) diff --git a/app/screens/sso/sso.js b/app/screens/sso/sso.js index 9dd78eaf0..920f93086 100644 --- a/app/screens/sso/sso.js +++ b/app/screens/sso/sso.js @@ -26,6 +26,7 @@ class SSO extends PureComponent { serverUrl: PropTypes.string.isRequired, ssoType: PropTypes.string.isRequired, actions: PropTypes.shape({ + getSession: PropTypes.func.isRequired, handleSuccessfulLogin: PropTypes.func.isRequired, setStoreFromLocalData: PropTypes.func.isRequired }).isRequired @@ -94,6 +95,7 @@ class SSO extends PureComponent { if (token) { this.setState({renderWebview: false}); const { + getSession, handleSuccessfulLogin, setStoreFromLocalData } = this.props.actions; @@ -101,6 +103,7 @@ class SSO extends PureComponent { Client4.setToken(token); setStoreFromLocalData({url: this.props.serverUrl, token}). then(handleSuccessfulLogin). + then(getSession). then(this.goToLoadTeam); } });