
class Login extends React.Component {
    state = {
        redirectToReferrer: false
    };
    login = () => {
        fakeAuth.authenticate(() => {
            this.setState({ redirectToReferrer: true });
        });
    };
    rendLoginRedirectLink = (page) => {
        return (
            <div>
                <p>You must log in to view the page at {page}</p>
                <button onClick={this.login}>Log in</button>
            </div>
        );
    };
    rendLogin = () => {
        return (
            <div>
                <button onClick={this.login}>Log in</button>
            </div>
        );
    };
    render() {
        const { from } = this.props.location.state || { from: { pathname: "/" } };
        const { redirectToReferrer } = this.state;

        if (redirectToReferrer) {
            return <Redirect to={from} />;
        }

        if (this.props.location.state) {
            return this.rendLoginRedirectLink(from.pathname);
        } else {
            return this.rendLogin();
        }
        
    }
}