Skip to main content

Miscellaneous

Redux FAQ: Miscellaneous​

Are there any larger, “real” Redux projects?​

Yes, lots of them! To name just a few:

And many, many more!

Further information​

Documentation

Discussions

How can I implement authentication in Redux?​

Authentication is essential to any real application. When going about authentication you must keep in mind that nothing changes with how you should organize your application and you should implement authentication in the same way you would any other feature. It is relatively straightforward:

  1. Create an auth slice with createSlice that holds the current user and token (or a flag indicating whether the user is logged in), plus loading and error fields for the login request.

  2. Make the login request either with an RTK Query mutation or with a createAsyncThunk that takes the credentials and returns the token. Handle the pending, fulfilled, and rejected cases in the slice's extraReducers (or with addMatcher for the mutation's lifecycle actions) to save the token or the error message.

  3. Read the token from the store when making other requests. With RTK Query, do this in baseQuery's prepareHeaders callback, which receives getState. For other code that needs the token outside a component, see How can I use the Redux store in non-component files?.

  4. If you want the session to survive a page reload, persist the token from a listener middleware effect that runs when the login succeeds, and read it back into preloadedState when you create the store.

Further information​

Documentation

Articles