mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2024-04-21 12:32:08 +00:00
bugfix (redirect): fixing redirect loop - #55
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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> );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user