Commit 5cce46e1 authored by David Haynes's avatar David Haynes 🙆

Auth check added into routes, token passed to children

- whee optimization
parent ae2836ab
Pipeline #3560 passed with stage
in 1 minute and 12 seconds
......@@ -27,7 +27,11 @@ class AuthButton extends React.Component {
render() {
const { is_auth, error } = this.state;
if (error) {
return <div>Error: {error.message}</div>;
return (
<Button outline color="accent">
Error: {error.message}
</Button>
);
} else {
return (
<div>
......
......@@ -10,14 +10,57 @@ import {
const NavBarWithRouter = withRouter(props => <NavBar {...props} />);
const Routes = () => (
<div>
<NavBarWithRouter />
<Route path="/" exact component={HomePage} />
<Route path="/dhaynes" component={DhaynesPage} />
<Route path="/about" component={AboutPage} />
<Route path="/debug" component={DebugCRUD} />
</div>
);
class Routes extends React.Component {
constructor(props) {
super(props);
this.state = {
error: null,
authToken: null
};
}
componentDidMount() {
fetch("/auth/token")
.then(res => res.json())
.then(
result => {
this.setState({
authToken: result.token
});
},
error => {
this.setState({
error
});
}
);
}
render() {
const { authToken } = this.state;
return (
<div>
<NavBarWithRouter />
<Route
path="/"
exact
render={props => <HomePage {...props} authToken={authToken} />}
/>
<Route
path="/dhaynes"
render={props => <DhaynesPage {...props} authToken={authToken} />}
/>
<Route
path="/about"
render={props => <AboutPage {...props} authToken={authToken} />}
/>
<Route
path="/debug"
render={props => <DebugCRUD {...props} authToken={authToken} />}
/>
</div>
);
}
}
export default Routes;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment