Store Credentials in Redux store is a good practice? Store Credentials in Redux store is a good practice? reactjs reactjs

Store Credentials in Redux store is a good practice?


No. It is not a good practise. If you wish to store user sessions better using cookie sessions to store JWT incase of React.js.

In case of react-native using react-native-keychain to store your passwords that too I would recommend as JWT token or Crypted text and not as plain text.

Your implementation mostly depends on your back end. If your using libraries like passport.js ( in case of node.js server) you use the crypt token to authorise requests. But whatever means you have to do auth don't store it in state plainly.


Using Modern Storage API will help you.

Cause when you Fetched your auth data in Redux Store, if page is refreshed or history moves(back || go), then Store Values are no longer exist. and your app will requests Auth data after refresh .. refresh ..

...

Using window.sessionStorage can remains data after refresh or history move.

  [AFTER LOGIN EVENT]    window.sessionStorage.setItem(key,vlaue)  [AFTER LOGOUT EVENT]    window.sessionStorage.clear() <- removes all records in sessionStorage.    window.sessionStorage.removeItem(key)