Skip to content

Instantly share code, notes, and snippets.

@phedkvist
Created May 27, 2019 20:00
Show Gist options
  • Save phedkvist/4da85e31eccefa1382f2f3b001e9b8fc to your computer and use it in GitHub Desktop.
Save phedkvist/4da85e31eccefa1382f2f3b001e9b8fc to your computer and use it in GitHub Desktop.
interface Props extends RouteComponentProps {}
interface State {
redirectToReferrer: boolean;
}
class Login extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
redirectToReferrer: false
};
}
login = () => {
fakeAuth.authenticate(() => {
this.setState({ redirectToReferrer: true });
});
};
render() {
let { from } = this.props.location.state || { from: { pathname: "/" } };
let { redirectToReferrer } = this.state;
if (redirectToReferrer) return <Redirect to={from} />;
return (
<div>
<p>You must log in to view the page at {from.pathname}</p>
<button onClick={this.login}>Log in</button>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment