B
B
bpGusar2018-05-13 18:25:32
JavaScript
bpGusar, 2018-05-13 18:25:32

How to check authorization in react router?

There is a backing on java, authorization takes place on it and cookies are sent to the client. What needs to be done with react router so that the user cannot get to this or that page if he is not logged in?
I also read about JWT but I don’t understand how to use it.
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2018-05-13
@bpGusar

An example of a private route . I have taken from "state.session.user" - you can check cookie or jwt.
For cookies - document.cookie
for jwt - just jwt.decode function and pass token as parameter.
more details about the private route are in the video . (52:40)

A
Andrey Okhotnikov, 2018-05-16
@tsepen

It is necessary to save cookies from the user state when the application is initialized, and then you need to check the page - if there is a user, then render the desired component, and if not, then redirect, for example, to the authorization page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question