Skip to content

Commit

Permalink
Save credentials immediately after login (mattermost#1703)
Browse files Browse the repository at this point in the history
* Save credentials immediately after login

* Add mock app class to login.test.js
  • Loading branch information
csduarte authored and hmhealey committed May 25, 2018
1 parent dd346db commit 5604836
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/actions/views/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import {getDataRetentionPolicy} from 'mattermost-redux/actions/general';
import {GeneralTypes} from 'mattermost-redux/action_types';
import {Client4} from 'mattermost-redux/client';
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';

import {ViewTypes} from 'app/constants';
import {app} from 'app/mattermost';

export function handleLoginIdChanged(loginId) {
return async (dispatch, getState) => {
Expand All @@ -27,9 +29,14 @@ export function handlePasswordChanged(password) {

export function handleSuccessfulLogin() {
return async (dispatch, getState) => {
const {config, license} = getState().entities.general;
const state = getState();
const {config, license} = state.entities.general;
const token = Client4.getToken();
const url = Client4.getUrl();
const deviceToken = state.entities.general.deviceToken;
const currentUserId = getCurrentUserId(state);

app.setAppCredentials(deviceToken, currentUserId, token, url);

dispatch({
type: GeneralTypes.RECEIVED_APP_CREDENTIALS,
Expand Down
6 changes: 6 additions & 0 deletions app/actions/views/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ jest.mock('react-native-fetch-blob/fs', () => ({
},
}));

jest.mock('app/mattermost', () => ({
app: {
setAppCredentials: () => jest.fn(),
},
}));

const mockStore = configureStore([thunk]);

describe('Actions.Views.Login', () => {
Expand Down

0 comments on commit 5604836

Please sign in to comment.