allow unprotected pages

This commit is contained in:
Sebastian Sdorra
2018-07-13 10:57:11 +02:00
parent 8ff84abf67
commit 5c59c6bac6
19 changed files with 567 additions and 450 deletions

View File

@@ -0,0 +1,56 @@
//@flow
import React from "react";
import { connect } from "react-redux";
import { Redirect } from "react-router-dom";
import { logout, isAuthenticated } from "../modules/auth";
import ErrorPage from "../components/ErrorPage";
import Loading from "../components/Loading";
type Props = {
loading: boolean,
authenticated: boolean,
error?: Error,
logout: () => void
};
class Logout extends React.Component<Props> {
componentDidMount() {
this.props.logout();
}
render() {
const { authenticated, loading, error } = this.props;
// TODO logout is called twice
if (error) {
return (
<ErrorPage
title="Logout failed"
subtitle="Something went wrong durring logout"
error={error}
/>
);
} else if (loading || authenticated) {
return <Loading />;
} else {
return <Redirect to="/login" />;
}
}
}
const mapStateToProps = state => {
let mapped = state.auth.logout || {};
mapped.authenticated = isAuthenticated(state);
return mapped;
};
const mapDispatchToProps = dispatch => {
return {
logout: () => dispatch(logout())
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(Logout);