Logout (#60)
- logout - changed default server to open.rocket.chat * fixed server change bug
This commit is contained in:
parent
a2b4e39a05
commit
6d4e6f0c6c
|
@ -6,6 +6,7 @@ import { connect } from 'react-redux';
|
||||||
|
|
||||||
import realm from '../lib/realm';
|
import realm from '../lib/realm';
|
||||||
import { setServer } from '../actions/server';
|
import { setServer } from '../actions/server';
|
||||||
|
import { logout } from '../actions/login';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
scrollView: {
|
scrollView: {
|
||||||
|
@ -39,13 +40,15 @@ const styles = StyleSheet.create({
|
||||||
@connect(state => ({
|
@connect(state => ({
|
||||||
server: state.server.server
|
server: state.server.server
|
||||||
}), dispatch => ({
|
}), dispatch => ({
|
||||||
selectServer: server => dispatch(setServer(server))
|
selectServer: server => dispatch(setServer(server)),
|
||||||
|
logout: () => dispatch(logout())
|
||||||
}))
|
}))
|
||||||
export default class Sidebar extends Component {
|
export default class Sidebar extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
server: PropTypes.string.isRequired,
|
server: PropTypes.string.isRequired,
|
||||||
selectServer: PropTypes.func.isRequired,
|
selectServer: PropTypes.func.isRequired,
|
||||||
navigation: PropTypes.object.isRequired
|
navigation: PropTypes.object.isRequired,
|
||||||
|
logout: PropTypes.func.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
|
@ -100,13 +103,20 @@ export default class Sidebar extends Component {
|
||||||
{...this.props}
|
{...this.props}
|
||||||
onItemPress={this.onItemPress}
|
onItemPress={this.onItemPress}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Text style={styles.serverTitle}>SERVERS</Text>
|
|
||||||
<FlatList
|
<FlatList
|
||||||
data={this.state.servers}
|
data={this.state.servers}
|
||||||
renderItem={this.renderItem}
|
renderItem={this.renderItem}
|
||||||
keyExtractor={item => item.id}
|
keyExtractor={item => item.id}
|
||||||
/>
|
/>
|
||||||
|
<TouchableHighlight
|
||||||
|
onPress={() => { this.props.logout(); }}
|
||||||
|
>
|
||||||
|
<View style={styles.serverItem}>
|
||||||
|
<Text>
|
||||||
|
Logout
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</TouchableHighlight>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
|
|
|
@ -105,7 +105,7 @@ const realm = new Realm({
|
||||||
export default realm;
|
export default realm;
|
||||||
|
|
||||||
// realm.write(() => {
|
// realm.write(() => {
|
||||||
// realm.create('servers', { id: 'https://demo.rocket.chat', current: false }, true);
|
// realm.create('servers', { id: 'https://open.rocket.chat', current: false }, true);
|
||||||
// realm.create('servers', { id: 'http://localhost:3000', current: false }, true);
|
// realm.create('servers', { id: 'http://localhost:3000', current: false }, true);
|
||||||
// realm.create('servers', { id: 'http://10.0.2.2:3000', current: false }, true);
|
// realm.create('servers', { id: 'http://10.0.2.2:3000', current: false }, true);
|
||||||
// });
|
// });
|
||||||
|
|
|
@ -20,6 +20,7 @@ const call = (method, ...params) => new Promise((resolve, reject) => {
|
||||||
resolve(data);
|
resolve(data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
const TOKEN_KEY = 'reactnativemeteor_usertoken';
|
||||||
|
|
||||||
const RocketChat = {
|
const RocketChat = {
|
||||||
createChannel({ name, users, type }) {
|
createChannel({ name, users, type }) {
|
||||||
|
@ -29,7 +30,6 @@ const RocketChat = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async getUserToken() {
|
async getUserToken() {
|
||||||
const TOKEN_KEY = 'reactnativemeteor_usertoken';
|
|
||||||
try {
|
try {
|
||||||
return await AsyncStorage.getItem(TOKEN_KEY);
|
return await AsyncStorage.getItem(TOKEN_KEY);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -408,8 +408,10 @@ const RocketChat = {
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
logout() {
|
logout({ server }) {
|
||||||
return AsyncStorage.clear();
|
Meteor.logout();
|
||||||
|
AsyncStorage.removeItem(TOKEN_KEY);
|
||||||
|
AsyncStorage.removeItem(`${ TOKEN_KEY }-${ server }`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ const getServer = state => state.server.server;
|
||||||
const loginCall = args => (args.resume ? RocketChat.login(args) : RocketChat.loginWithPassword(args));
|
const loginCall = args => (args.resume ? RocketChat.login(args) : RocketChat.loginWithPassword(args));
|
||||||
const registerCall = args => RocketChat.register(args);
|
const registerCall = args => RocketChat.register(args);
|
||||||
const setUsernameCall = args => RocketChat.setUsername(args);
|
const setUsernameCall = args => RocketChat.setUsername(args);
|
||||||
|
const logoutCall = args => RocketChat.logout(args);
|
||||||
|
|
||||||
const getToken = function* getToken() {
|
const getToken = function* getToken() {
|
||||||
const currentServer = yield select(getServer);
|
const currentServer = yield select(getServer);
|
||||||
|
@ -132,6 +133,11 @@ const handleSetUsernameRequest = function* handleSetUsernameRequest({ credential
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleLogout = function* handleLogout() {
|
||||||
|
const server = yield select(getServer);
|
||||||
|
yield call(logoutCall, { server });
|
||||||
|
};
|
||||||
|
|
||||||
const root = function* root() {
|
const root = function* root() {
|
||||||
yield takeEvery(types.SERVER.CHANGED, handleLoginWhenServerChanges);
|
yield takeEvery(types.SERVER.CHANGED, handleLoginWhenServerChanges);
|
||||||
yield takeLatest(types.LOGIN.REQUEST, handleLoginRequest);
|
yield takeLatest(types.LOGIN.REQUEST, handleLoginRequest);
|
||||||
|
@ -142,5 +148,6 @@ const root = function* root() {
|
||||||
yield takeLatest(types.LOGIN.REGISTER_SUCCESS, handleRegisterSuccess);
|
yield takeLatest(types.LOGIN.REGISTER_SUCCESS, handleRegisterSuccess);
|
||||||
yield takeLatest(types.LOGIN.SET_USERNAME_SUBMIT, handleSetUsernameSubmit);
|
yield takeLatest(types.LOGIN.SET_USERNAME_SUBMIT, handleSetUsernameSubmit);
|
||||||
yield takeLatest(types.LOGIN.SET_USERNAME_REQUEST, handleSetUsernameRequest);
|
yield takeLatest(types.LOGIN.SET_USERNAME_REQUEST, handleSetUsernameRequest);
|
||||||
|
yield takeLatest(types.LOGOUT, handleLogout);
|
||||||
};
|
};
|
||||||
export default root;
|
export default root;
|
||||||
|
|
|
@ -68,7 +68,7 @@ export default class NewServerView extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
defaultServer: 'https://demo.rocket.chat',
|
defaultServer: 'https://open.rocket.chat',
|
||||||
editable: true,
|
editable: true,
|
||||||
text: ''
|
text: ''
|
||||||
};
|
};
|
||||||
|
|
|
@ -94,6 +94,14 @@ export default class RoomsListView extends React.Component {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(props) {
|
||||||
|
if (this.props.server !== props.server) {
|
||||||
|
this.data.removeListener(this.updateState);
|
||||||
|
this.data = realm.objects('subscriptions').filtered('_server.id = $0', props.server).sorted('_updatedAt', true);
|
||||||
|
this.data.addListener(this.updateState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.data.removeAllListeners();
|
this.data.removeAllListeners();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue