react-router-role-authorization icon indicating copy to clipboard operation
react-router-role-authorization copied to clipboard

How can I add this on universal(isomorphic) react web apps?

Open aseem2625 opened this issue 9 years ago • 3 comments

I was trying to figure out a way but it doesn't seem to work for me if I try to put this on server side.

I am using this boilerplate. https://github.com/erikras/react-redux-universal-hot-example/

In server.js, I added

class Profile extends AuthorizedComponent {
  render() {
    return (
      <div className="profile-container">
        <RouteHandler {...this.props} />;
      </div>
    );
  }
}

And in same file, I replaced

        <Provider store={store} key="provider">
          <ReduxAsyncConnect {...renderProps} />
        </Provider>
          <Profile routes={getRoutes(store)}>
            <Provider store={store} key="provider">
              <ReduxAsyncConnect {...renderProps} />
            </Provider>
          </Profile>

For starting, I modified routes.js as

      <Route path="about" component={About} authorize={['admin']}/>
      <Route path="login" component={Login} authorize={['employee']}/>
      <Route path="survey" component={Survey} authorize={['employee', 'admin']}/>
      <Route path="widgets" component={Widgets}/>

and Rest I've made RoleAwareComponent.js and AuthorizedComponent.js and RouterHandler.js as mentioned in the article http://frontendinsights.com/role-based-authorization-using-react-router/

These things doesn't seem to work.

Can you please direct me if this is the correct way to add Role Based Authorization on server side? I can give further info if needed.

Thanks

aseem2625 avatar Sep 16 '16 12:09 aseem2625

Hi, thanks for raising this issue! To be honest I didn't try it in the isomorphic app yet... I will test it and fix the issue if needed.

burczu avatar Sep 19 '16 10:09 burczu

Thanks @burczu I am eager to know its working with isomorphic react app.

On a side note: Also, I liked your article at http://frontendinsights.com/role-based-authorization-using-react-router/ Conceptually is good. As a feedback, I think it can be improved if the context of the project setup is given. For eg: We've several ways of setting up Routes.js and other things in React. 😃

aseem2625 avatar Sep 19 '16 12:09 aseem2625

Hi @burczu Have you managed to make it work on isomorphic app ?

jaybe78 avatar Jan 19 '17 14:01 jaybe78