From 442017c0eacb4ee1b904d03434f14029fb623220 Mon Sep 17 00:00:00 2001 From: Mickael KERJEAN Date: Wed, 9 May 2018 15:10:51 +1000 Subject: [PATCH] bugfix (redirect): fixing redirect loop - #55 --- client/model/session.js | 2 +- client/pages/homepage.js | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) 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 ( -
- ); + if(this.state.redirection !== null){ + return ( ); + } + return (
); } }