diff --git a/src/containers/GoogleLogin/index.js b/src/containers/GoogleLogin/index.js index 61b69cf2c6f7001f15750df3c54aab22074dff90..72e42baf4682ff70ac6251847feccfa0ff2c71c5 100644 --- a/src/containers/GoogleLogin/index.js +++ b/src/containers/GoogleLogin/index.js @@ -8,17 +8,17 @@ import request from '../../utils/request'; class GoogleLogin extends Component { static onFailure() { - // TODO handle error + // TODO: handle error // console.error(err); } static onRequest() { - // TODO add spinner + // TODO: add spinner // console.log('loading...'); } static checkToken() { - return localStorage.gat && new Date() < localStorage.ed; + return localStorage.gat && new Date() < new Date(parseInt(localStorage.ed, 10)); } static loggedIn() { @@ -54,7 +54,7 @@ class GoogleLogin extends Component { this.setState({ loggedIn: true }); } }).catch(() => { - // TODO handle invalid token error + // TODO: handle invalid token error // console.error(err); }); } @@ -103,7 +103,7 @@ class GoogleLogin extends Component { }; } - onSuccess = (authResponse, user, goBack) => { + onSuccess = (authResponse, redirect, user) => { localStorage.setItem('git', authResponse.id_token); localStorage.setItem('gat', authResponse.access_token); localStorage.setItem('ed', authResponse.expires_at); @@ -116,8 +116,8 @@ class GoogleLogin extends Component { } this.setState({ loggedIn: true }); - if (goBack) { - // TODO go back to previous page + if (redirect) { + // TODO: go back to previous page this.props.router.push('/'); } }; @@ -125,7 +125,11 @@ class GoogleLogin extends Component { refreshToken = () => { window.gapi.auth2.getAuthInstance().currentUser.get() .reloadAuthResponse().then((authResponse) => { - this.onSuccess(authResponse); + let redirect = false; + if (this.props.router.getCurrentLocation().pathname === '/login') { + redirect = true; + } + this.onSuccess(authResponse, redirect); }); }; @@ -150,7 +154,7 @@ class GoogleLogin extends Component { .then((res) => { const basicProfile = res.getBasicProfile(); const authResponse = res.getAuthResponse(); - this.onSuccess(authResponse, basicProfile, true); + this.onSuccess(authResponse, true, basicProfile); }, err => GoogleLogin.onFailure(err) ); @@ -159,7 +163,7 @@ class GoogleLogin extends Component { }; signOut = () => { - // TODO prevent logout button from being pressed before gapi.auth2.init + // TODO: prevent logout button from being pressed before gapi.auth2.init // has loaded if (!this.state.disabled) { window.gapi.auth2.getAuthInstance().signOut();