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

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 { ...@@ -27,7 +27,11 @@ class AuthButton extends React.Component {
render() { render() {
const { is_auth, error } = this.state; const { is_auth, error } = this.state;
if (error) { if (error) {
return <div>Error: {error.message}</div>; return (
<Button outline color="accent">
Error: {error.message}
</Button>
);
} else { } else {
return ( return (
<div> <div>
......
...@@ -10,14 +10,57 @@ import { ...@@ -10,14 +10,57 @@ import {
const NavBarWithRouter = withRouter(props => <NavBar {...props} />); const NavBarWithRouter = withRouter(props => <NavBar {...props} />);
const Routes = () => ( 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> <div>
<NavBarWithRouter /> <NavBarWithRouter />
<Route path="/" exact component={HomePage} /> <Route
<Route path="/dhaynes" component={DhaynesPage} /> path="/"
<Route path="/about" component={AboutPage} /> exact
<Route path="/debug" component={DebugCRUD} /> 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> </div>
); );
}
}
export default Routes; 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