Add warning about invalid token
This commit is contained in:
parent
7cdfc8e11f
commit
a4e0b2b69d
1 changed files with 22 additions and 4 deletions
26
app/index.js
26
app/index.js
|
@ -7,13 +7,14 @@ import BusyIndicator from 'react-native-busy-indicator';
|
||||||
import token from './api/token';
|
import token from './api/token';
|
||||||
import { checkToken } from './api/CircleCI';
|
import { checkToken } from './api/CircleCI';
|
||||||
|
|
||||||
require('moment-duration-format');
|
import 'moment-duration-format';
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Navigator,
|
Navigator,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Platform,
|
Platform,
|
||||||
View
|
View,
|
||||||
|
Alert
|
||||||
} = React;
|
} = React;
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
@ -28,6 +29,10 @@ const styles = StyleSheet.create({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const LOGGED_IN_ROUTE = RouteMaster.get('HOME');
|
||||||
|
const LOGIN_ROUTE = RouteMaster.get('LOGIN');
|
||||||
|
|
||||||
|
|
||||||
export default class App extends React.Component {
|
export default class App extends React.Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
@ -49,18 +54,31 @@ export default class App extends React.Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warnInvalidToken() {
|
||||||
|
Alert.alert(
|
||||||
|
'Token Invalidated',
|
||||||
|
'The token you used previously is now invalid. Please generate a new one in your account settings.',
|
||||||
|
[
|
||||||
|
{ text: 'ok' }
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
token.get().then(function (CIToken) {
|
token.get().then(function (CIToken) {
|
||||||
if (!CIToken) {
|
if (!CIToken) {
|
||||||
this.setState({
|
this.setState({
|
||||||
initialRoute: RouteMaster.get('HOME')
|
initialRoute: LOGIN_ROUTE
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkToken(CIToken).then(function (isValid) {
|
checkToken(CIToken).then(function (isValid) {
|
||||||
this.setState({
|
this.setState({
|
||||||
initialRoute: isValid ? RouteMaster.get('HOME') : RouteMaster.get('LOGIN')
|
initialRoute: isValid ? LOGGED_IN_ROUTE : LOGIN_ROUTE
|
||||||
});
|
});
|
||||||
|
if (!isValid) {
|
||||||
|
this.warnInvalidToken();
|
||||||
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue