mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
improve authentication
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user