diff --git a/client/model/session.js b/client/model/session.js index d8130bfd..9e2a01cf 100644 --- a/client/model/session.js +++ b/client/model/session.js @@ -1,7 +1,7 @@ import { http_get, http_post, http_delete } from '../helpers/'; class SessionManager{ - isLogged(){ + isLoggedIn(){ let url = '/api/session' return http_get(url) .then(data => data.result); diff --git a/client/pages/homepage.js b/client/pages/homepage.js index 8b827e02..226497d8 100644 --- a/client/pages/homepage.js +++ b/client/pages/homepage.js @@ -1,4 +1,5 @@ import React from 'react'; +import { Redirect } from 'react-router'; import { Session } from '../model/'; import { Loader } from '../components/'; @@ -6,21 +7,28 @@ import { Loader } from '../components/'; export class HomePage extends React.Component { constructor(props){ super(props); + this.state = { + redirection: null + }; } componentDidMount(){ - Session.isLogged() + Session.isLoggedIn() .then((res) => { - if(res && res.result === true){ - this.props.history.push('/files'); + if(res === true){ + this.setState({redirection: "/files"}); }else{ - this.props.history.push('/login'); + this.setState({redirection: "/login"}); } + }) + .catch((err) => { + this.setState({redirection: "/login"}); }); } render() { - return ( -