forked from acouzens/open5gs
React HOCS is added
This commit is contained in:
parent
db473e8ed6
commit
2f2da5ffc4
|
@ -0,0 +1,17 @@
|
|||
import React from 'react';
|
||||
|
||||
export default Page => class DefaultPage extends React.Component {
|
||||
static getInitialProps (ctx) {
|
||||
const loggedUser = 'admin'
|
||||
const pageProps = Page.getInitialProps && Page.getInitialProps(ctx);
|
||||
return {
|
||||
...pageProps,
|
||||
loggedUser,
|
||||
isAuthenticated: !!loggedUser
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (<Page { ...this.props } />);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
import React from 'react';
|
||||
import defaultPage from './defaultPage';
|
||||
|
||||
const securePageHoc = Page => class SecurePage extends React.Component {
|
||||
static getInitialProps (ctx) {
|
||||
return Page.getInitialProps && Page.getInitialProps(ctx);
|
||||
}
|
||||
|
||||
render () {
|
||||
return <Page { ...this.props } />
|
||||
}
|
||||
}
|
||||
|
||||
export default Page => defaultPage(securePageHoc(Page));
|
|
@ -1,14 +1,18 @@
|
|||
import React from 'react';
|
||||
import Link from 'next/link';
|
||||
import defaultPage from '../hocs/defaultPage';
|
||||
|
||||
const Index = () => {
|
||||
const Index = ({ loggedUser, isAuthenticated }) => {
|
||||
return (
|
||||
<div>
|
||||
<h1>Hello Worlds!</h1>
|
||||
{ loggedUser }
|
||||
{isAuthenticated && <p>Authenticated!!</p>}
|
||||
{!isAuthenticated && <p>Not Authriozed</p>}
|
||||
<p><Link href='/login'><a>Login</a></Link></p>
|
||||
<p><Link href='/logout'><a>Logout</a></Link></p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default (Index);
|
||||
export default defaultPage(Index);
|
Loading…
Reference in New Issue