bugfix (redirect): fixing redirect loop - #55

This commit is contained in:
Mickael KERJEAN
2018-05-09 15:10:51 +10:00
parent 04e308ded8
commit 442017c0ea
2 changed files with 16 additions and 8 deletions
+1 -1
View File
@@ -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);
+15 -7
View File
@@ -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 (
<div> <Loader /> </div>
);
if(this.state.redirection !== null){
return ( <Redirect to={this.state.redirection} /> );
}
return ( <div> <Loader /> </div> );
}
}