0
You can implement private routes by receiving a JWT token in the header and body information in Reactjs with React Router?
0
You can implement private routes by receiving a JWT token in the header and body information in Reactjs with React Router?
1
I use it this way in my applications
const PrivateRoute = ({component: Component, ...rest}) => {
return (
<Route {...rest} render={props => (
isAuth() ?
<Component {...props} />
: <Redirect to="/signIn" />
)} />
);
};
This isAuth() is a method that comes from a file I use to see if it is in localstorage
module.exports = {
isAuth(){
var user = localStorage.getItem('current_user')
if(!user)
return false
return true
}
}
And in your route file only you use Private route when you want to have an authenticated route
<PrivateRoute path="/suaRota" component={ SeuComponent } />
Browser other questions tagged javascript react jwt react-router router
You are not signed in. Login or sign up in order to post.
Yes it is possible.
– Chance
know some link with tutorial or sample code?
– Vinicius Dantas
So unfortunately I have no public project with this content, but if I’m not mistaken in the channel of Rocketseat will have some content next to that.
– Chance