Comments (3)
@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.
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.
@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)
- [Possible Bug] Async Validation in a multi-step form HOT 1
- How to make chunk js with react-router HOT 1
- Error in UserAuthWrapper
- Hande logout when expired token in axios interceptors but not redirect to login page HOT 2
- Misleading naming of authenticatedSelector HOT 2
- Example with react 16.x HOT 1
- Reducer not yet defined HOT 2
- Usage with react-cookies
- not running when am trying do npm start HOT 1
- connectedReduxRedirect is missing HOT 1
- Deprecated lifecycle method in redirect.js HOT 7
- Doesn't work with latest react HOT 3
- Type {} is missing the following properties from type Readonly<InjectedAuthProps> HOT 1
- ES6 Module - Error when using with Electron HOT 2
- redirect.js replace UNSAFE_componentWillMount with componentDidMount HOT 6
- No question mark befor query param on redirect HOT 2
- Versioning Order HOT 4
- React-router v6 HOT 9
- Infinite loop (redirect ) with nesting wrappers HOT 1
- Call for mantainers! HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-auth-wrapper.