From a2e9473d9e4c68b3c1735bf14ee3ea2c96d8f276 Mon Sep 17 00:00:00 2001 From: patlub Date: Thu, 15 Feb 2018 16:04:54 +0300 Subject: [PATCH] Login component does not check if user is logged in on load. --- app/js/components/manageApps/Login.jsx | 30 ++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/app/js/components/manageApps/Login.jsx b/app/js/components/manageApps/Login.jsx index edbb918..bcad400 100644 --- a/app/js/components/manageApps/Login.jsx +++ b/app/js/components/manageApps/Login.jsx @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import { hashHistory } from 'react-router'; import axios from 'axios'; +import { ApiHelper } from '../../helpers/apiHelper'; import { Form, Button, FormControl, FormGroup, Col, ControlLabel, Checkbox, Nav, Modal } from 'react-bootstrap'; class Login extends Component { constructor(props) { @@ -8,15 +9,39 @@ class Login extends Component { this.state = { username: '', password: '', - show: false - } + show: false, + checkLoggedInComplete: false + }; + this.handleLogin = this.handleLogin.bind(this); this.handleShow = this.handleShow.bind(this); this.handleClose = this.handleClose.bind(this); } + + componentWillMount(){ + this.checkLoginStatus(); + } + + checkLoginStatus(){ + this.fetchLocation('/v1/session').then((response) => { + this.setState({checkLoggedInComplete: true}); + response.authenticated ? hashHistory.push('/') : null; + }); + } + + fetchLocation(url) { + const apiHelper = new ApiHelper(null); + return new Promise(function(resolve, reject) { + apiHelper.get(url).then(response => { + resolve(response); + }); + }); + } + handleClose() { this.setState({ show: false }); } + handleShow() { this.setState({ show: true }); } @@ -47,6 +72,7 @@ class Login extends Component { render() { return ( + this.state.checkLoggedInComplete &&