hi do u know how to implement authorization if the user is successfully logged In i had to keep restriction to one page (i.e one component page) to access that page he should know the admin Login and password . so, basically need to implement authorization for that one page
like
after the successful login if the user wants to access one of the posts page (localhost/posts) the page should be blocked and only admins can access to that page
In the user database you should store the role of the user as well so that when the user logs in, the backend server will return the user obect something like below. Then you can conditionally route the user based on the role using react-router.
{username: 'Robin' role:'Admin' id: 234343, token:'454jklkjflk04i54i5'}
use Redirect component from react-router-dom , if user is not logged in redirect him to login page . if you're using local storage for that , you can do it like so { !localStorage.getItem('token') ? <Redirect to="login" /> : <Posts /> } Hope this Help !
Arun Kumar
developer
mahendher ma
More technically and for robust implementation the concept is called Access Control List (ACL). This (levelup.gitconnected.com/access-control-in-a-reac…) article will give you more insights into the concept.
Router with ACL github.com/AlanWei/react-acl-router
Also, googling 'Access control list react' will bring up many relevant articles and npm packages that might be useful for your requirement.