Coder Social home page Coder Social logo

Comments (3)

mjrussell avatar mjrussell commented on September 15, 2024

@omago thats an interesting use case and the auth wrapper in its current form probably does not solve this easily. The routes will always match first and you cant change the routes based on the store in React Router, so listing them sequentially wont work in this case.

One option you could do is use the auth wrapper for the / route as just the authentication, not authorization.

So you'd have a route like:
<Route path="/" component={UserIsAuthenticated(AdvertiserLayout)} />

Then inside the Advertiser layout, you have the authData as a prop and can do something like the following in your render:

render() {
  if (this.props.authData.isAdmin) {
    return <AdminAdvertiserLayout />;
  } else {
    return <AdvertiserLayout />;
  }
}

from redux-auth-wrapper.

omago avatar omago commented on September 15, 2024

Hi Matthew,

Thanks for your reply, i will try your approach. The best would be to implement authentication and autorization in a way that they are independent. Once again, thanks for your answer.

from redux-auth-wrapper.

mjrussell avatar mjrussell commented on September 15, 2024

@omago if you have any suggestions or improvements to the library that you think would make this easier definitely let me know! In my apps I typically route admins/regular users to different locations rather than displaying different data on the same route.

You could also write your own HOC that behaves similar to and takes in two different components and decides with an auth check on which to render.

from redux-auth-wrapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.