From a4e0b2b69d02cda3c1e273d91852b685e2dc8038 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 5 May 2016 21:51:49 +0100 Subject: [PATCH] Add warning about invalid token --- app/index.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/index.js b/app/index.js index 74d9e7c..61140c6 100644 --- a/app/index.js +++ b/app/index.js @@ -7,13 +7,14 @@ import BusyIndicator from 'react-native-busy-indicator'; import token from './api/token'; import { checkToken } from './api/CircleCI'; -require('moment-duration-format'); +import 'moment-duration-format'; const { Navigator, StyleSheet, Platform, - View + View, + Alert } = React; 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 { constructor() { 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() { token.get().then(function (CIToken) { if (!CIToken) { this.setState({ - initialRoute: RouteMaster.get('HOME') + initialRoute: LOGIN_ROUTE }); return; } checkToken(CIToken).then(function (isValid) { 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)); }