improve authentication

This commit is contained in:
Sebastian Sdorra
2018-07-11 21:01:29 +02:00
parent 1b6df5ee08
commit b604d613a3
16 changed files with 359 additions and 110 deletions

View File

@@ -1,45 +1,50 @@
import React, { Component } from "react";
import Main from "./Main";
import Login from "./Login";
import { getIsAuthenticated } from "../modules/login";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import { ThunkDispatch } from "redux-thunk";
import { fetchMe } from "../modules/me";
import "./App.css";
import Header from "../components/Header";
import PrimaryNavigation from "../components/PrimaryNavigation";
import Loading from "../components/Loading";
import Notification from "../components/Notification";
import Footer from "../components/Footer";
type Props = {
login: boolean,
username: string,
getAuthState: () => void,
me: any,
fetchMe: () => void,
loading: boolean
};
class App extends Component<Props> {
componentDidMount() {
this.props.getAuthState();
this.props.fetchMe();
}
render() {
const { login, loading } = this.props;
const { me, loading } = this.props;
let content;
let content = [];
let navigation;
if (loading) {
content = <div>Loading...</div>;
} else if (!login) {
content = <Login />;
content.push(<Loading />);
} else if (!me) {
content.push(<Login />);
} else {
content = <Main />;
content.push(<Main />, <Footer me={me} />);
navigation = <PrimaryNavigation />;
}
return (
<div className="App">
<Header>{navigation}</Header>
{content}
{content.map(c => {
return c;
})}
</div>
);
}
@@ -47,12 +52,12 @@ class App extends Component<Props> {
const mapDispatchToProps = (dispatch: ThunkDispatch) => {
return {
getAuthState: () => dispatch(getIsAuthenticated())
fetchMe: () => dispatch(fetchMe())
};
};
const mapStateToProps = state => {
return state.login || {};
return state.me || {};
};
export default withRouter(