User- Roles :: frontend :: Prashant
roles in front end section what condtion should use in front end that we can check roles::
Note01:: Basic concept understaood by prashant
export const Route
export default app
import {Route} from 'react-router-dom'
PrivateRoute.js
export const PrivateRoute = (props) => {
const isAuthorized = true
return(
?
<Route
path="/abc"
render={() => </Student>}
> : <Redirect to="login">
)
}
App.js
<PrivateRoute
isAuthorized={}
/>
</Route>
Note02:: Basic concept understaood for rest
({...rest})
Note 03::
({roles, hj,jjj, ...rest})
const gjhjk(props)
Note 04::
App.js
return
<Router>
jijo
</Router>
Note 06:
a = 2
2=== a
({path, component, h, h, ...rest})
{path: '', component: ''}
= props
Note 07:
PrivateRoute.js
// This is used to determine if a user is authenticated and
// if they are allowed to visit the page they navigated to.
// If they are: they proceed to the page
// If not: they are redirected to the login page.
import React from 'react'
import { Redirect, Route } from 'react-router-dom'
const PrivateRoute = ({ component: Component, ...rest }) => {
// Add your own authentication on the below line.
let user = JSON.parse(localStorage.getItem('user'));
const isLoggedIn = user ? true : false;
const isAuthorized = user ? true : false;
// const isAuthorized = rest.roles && rest.roles[0] && rest.roles.includes(user.role)
return (
<Route
{...rest}
render={props =>
isLoggedIn && isAuthorized ? (
<Component {...props} />
) : (
<Redirect to={{ pathname: '/login', state: { from: props.location } }} />
)
}
/>
)
}
export default PrivateRoute
made in backend by prashant - i think this is for the frontednd
.......................................................................................
const checkAuthorized = (roles) => {
user = localStorage.getItem('user')
roles.includes(user.role)
}
.......................................................................................
Comments
Post a Comment