Authentication Example
There are several ways to handle authentication with RTK Query. This is a very basic example of taking a JWT from a login mutation, then setting that in our store. We then use prepareHeaders
to inject the authentication headers into every subsequent request.
Dispatching an action to set the user state
This example dispatches a setCredentials
action to store the user and token information.
extraReducers
Using This example uses a matcher from the endpoint and extraReducers
in the authSlice
.