My current approach is to store jwt in localStorage, when the application starts, I load the token, trying to load user data with the token, if it fails, it simply redirects / login
Then I use jwt only in the api module, not in the store at all.
My Api module knows, based on requests, when to use a token, not
If the api module recognizes failed authentication, it also removes the token from localStorage .. so the next time it cannot be loaded.
My api module, which is also separate from redux, knows when to use jwt and when not.
To make this work more abstract, I created middleware that responds to every action if the payload is error and the value is Not Authenticated
this is an error that I pick up in the api module if the server response fails due to auth. actionCreator simply sends an error to catch , and the middleware responds to it.
So, actually it is up to you how to do this, all the code I'm talking about is ~ 100 LOC or so .. just some methods that handle these things.
source share