2019-05-19 21:22:01 +01:00
|
|
|
import * as React from 'react';
|
|
|
|
import {
|
|
|
|
Redirect, Route
|
|
|
|
} from "react-router-dom";
|
|
|
|
|
|
|
|
import { withAuthenticationContext } from './Context.js';
|
|
|
|
import * as Authentication from './Authentication';
|
|
|
|
|
|
|
|
class UnauthenticatedRoute extends React.Component {
|
|
|
|
render() {
|
2019-05-31 20:55:06 +01:00
|
|
|
const { authenticationContext, component:Component, ...rest } = this.props;
|
2019-05-19 21:22:01 +01:00
|
|
|
const renderComponent = (props) => {
|
2019-05-31 20:55:06 +01:00
|
|
|
if (authenticationContext.isAuthenticated()) {
|
2019-05-19 21:22:01 +01:00
|
|
|
return (<Redirect to={Authentication.fetchLoginRedirect()} />);
|
|
|
|
}
|
|
|
|
return (<Component {...props} />);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Route {...rest} render={renderComponent} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withAuthenticationContext(UnauthenticatedRoute);
|