private routes and redirecting

This commit is contained in:
Delucse
2020-12-03 12:09:01 +01:00
parent 5d9bfa97af
commit 80fd112658
7 changed files with 90 additions and 31 deletions
+8 -1
View File
@@ -25,6 +25,7 @@ export class Login extends Component {
constructor(props) {
super(props);
this.state = {
redirect: props.location.state ? props.location.state.from.pathname : null,
email: '',
password: '',
snackbar: false,
@@ -36,10 +37,16 @@ export class Login extends Component {
}
componentDidUpdate(props){
console.log(this.state.redirect);
const { message } = this.props;
if (message !== props.message) {
if(message.id === 'LOGIN_SUCCESS'){
this.props.history.goBack();
if(this.state.redirect){
this.props.history.push(this.state.redirect);
}
else{
this.props.history.goBack();
}
}
// Check for login error
else if(message.id === 'LOGIN_FAIL'){