Created
May 27, 2019 20:00
-
-
Save phedkvist/4da85e31eccefa1382f2f3b001e9b8fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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