Pull to refresh
6
0
Babichev Oleg @obabichev

Пользователь

Send message

React Token Auth

Reading time10 min
Views44K


Problem


Authorization is one of the first problems developers face upon starting a new project. And one of the most common types of authorization (from my experience) is the token-based authorization (usually using JWT).


From my perspective, this article looks like "what I wanted to read two weeks ago". My goal was to write minimalistic and reusable code with a clean and straightforward interface. I had the next requirements for my implementation of the auth management:


  • Tokens should be stored in local storage
  • Tokens should be restored on page reload
  • Access token should be passed in the network requests
  • After expiration access token should be updated by refresh token if the last one is presented
  • React components should have access to the auth information to render appropriate UI
  • The solution should be made with pure React (without Redux, thunk, etc..)
Read more →
Total votes 6: ↑4 and ↓2+2
Comments22

Information

Rating
5,271-st
Registered
Activity