-3

I want to store user access token and userID in local storage and also in the redux store, when a user login. We will receive the access token and userId from the API, when a user login.

Thanks in Advance.

  • 1
    Possible duplicate of [Storing Objects in HTML5 localStorage](https://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage) – wentjun Mar 13 '19 at 09:04
  • This question is very broad. What have you tried so far? Have you tried [implemented it yourself with a custom `subscribe` on the store](https://stackoverflow.com/questions/35305661/where-to-write-to-localstorage-in-a-redux-app)? – Tholle Mar 13 '19 at 09:04

1 Answers1

1

Saving to local storage and setting it to auth header

// Get token
const { token } = res.data;

// Set token to local storage
// Note: Local storage only stores strings
localStorage.setItem("jwtToken", token);

// Set token to Auth header - if you are using axios
axios.defaults.headers.common["Authorization"] = token;
Limbo
  • 101
  • 1
  • 12