Created
October 12, 2018 02:37
-
-
Save ryanbelke/a04a1433418a162d5a54c63b8ad3b8cb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* components/hocs/securePage.js */ | |
| import React from "react"; | |
| import PropTypes from "prop-types"; | |
| import defaultPage from "./defaultPage"; | |
| const securePageHoc = Page => | |
| class SecurePage extends React.Component { | |
| static propTypes = { | |
| isAuthenticated: PropTypes.bool.isRequired | |
| }; | |
| static getInitialProps(ctx) { | |
| return Page.getInitialProps && Page.getInitialProps(ctx); | |
| } | |
| render() { | |
| const { isAuthenticated } = this.props; | |
| return isAuthenticated ? <Page {...this.props} /> : "Not Authorized"; | |
| } | |
| }; | |
| export default Page => defaultPage(securePageHoc(Page)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment