Role based authorization in React
Carl Vitullo
1K20

const Authorization = (WrappedComponent, allowedRoles) =>

return class WithAuthorization extends React.Component { constructor(props) {

super(props)

this.state = { user: { name: ‘vcarl’, role: ‘admin’ } }

}

render() {

const { role } = this.state.user if (allowedRoles.includes(role)) {

return <WrappedComponent {…this.props} /> }

else {

return <h1>No page for you!</h1> } } }

Above syntax is not working for me. Do I need to include some babel plugin in my .babelrc ?

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.