verdnatura-chat/app/sagas/init.js

27 lines
738 B
JavaScript
Raw Normal View History

import { AsyncStorage } from 'react-native';
import { call, put, take } from 'redux-saga/effects';
import * as actions from '../actions';
import { setServer } from '../actions/server';
2017-11-13 13:19:24 +00:00
import { restoreToken } from '../actions/login';
import { APP } from '../actions/actionsTypes';
const restore = function* restore() {
try {
yield take(APP.INIT);
2017-11-13 13:19:24 +00:00
const token = yield call([AsyncStorage, 'getItem'], 'reactnativemeteor_usertoken');
if (token) {
yield put(restoreToken(token));
}
const currentServer = yield call([AsyncStorage, 'getItem'], 'currentServer');
if (currentServer) {
yield put(setServer(currentServer));
}
2017-11-13 13:19:24 +00:00
yield put(actions.appReady({}));
} catch (e) {
console.log(e);
}
};
export default restore;