Answer the question
In order to leave comments, you need to log in
How to write user authorization in React?
Hello. I have a REST API which also provides authorization. How can I organize this authorization in React? It's for the tokens. Then there are only two pages on the frontend: an entrance and a page with an account. I need to ensure that only an authorized user can view the account page. I found solutions with Redux, but my application doesn't need it. Is there an easier option? Could you describe step by step, or maybe throw off a code example? Thanks in advance
Answer the question
In order to leave comments, you need to log in
Log in to the server -> get a token -> check if the token is valid -> store the token in LocalStorage -> add the token to your subsequent secure requests -> store the user information in the Context (instead of Redux).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question