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
- Reddit: Large open source react/redux projects?
- HN: Is there any huge web application built using Redux?
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:
-
Create an
authslice withcreateSlicethat 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. -
Make the login request either with an RTK Query mutation or with a
createAsyncThunkthat takes the credentials and returns the token. Handle the pending, fulfilled, and rejected cases in the slice'sextraReducers(or withaddMatcherfor the mutation's lifecycle actions) to save the token or the error message. -
Read the token from the store when making other requests. With RTK Query, do this in
baseQuery'sprepareHeaderscallback, which receivesgetState. For other code that needs the token outside a component, see How can I use the Redux store in non-component files?. -
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
preloadedStatewhen you create the store.
Further information
Documentation
Articles
- Authentication with JWT by Auth0 (2016, uses
connectand hand-written thunks; the overall flow still applies)