Open bastiW opened 4 years ago
also we needed to change this on all other places where you make user of the user:
nextMiddleware(userFound(JSON.parse(user.toStorageString())));
onUserLoaded = (user) => {
this.props.store.dispatch(userFound(JSON.parse(user.toStorageString())));
};
export function getUserCallback(user) {
if (user && !user.expired) {
reduxStore.dispatch(userFound(JSON.parse(user.toStorageString())));
} else if (!user || (user && user.expired)) {
reduxStore.dispatch(userExpired());
}
return user;
}
I have created a fork here: https://github.com/bastiW/redux-oidc
I'd also like to get rid of non-serializable warning. We're using Redux Toolkit which includes serializable checks for state as a default dev-only middleware (https://redux-toolkit.js.org/api/other-exports#createserializablestateinvariantmiddleware) and I'll be happier without warnings which I should always ignore.
Any updates on this? I am also using the redux toolkit and the console is getting quite cluttered over here. I did manage to temporarily disable the serializable check, but this is not a valid fix for anything. This just gives me back my console.
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'
...
const store = configureStore(
{
reducer: YOUR_REDUCER(S)_HERE,
middleware: [
...getDefaultMiddleware({
serializableCheck: false
}),
...otherMiddlewares
],
devTools: process.env.NODE_ENV !== 'production' ? { CONFIG_GOES_HERE } : false
}
);
This disables the check for serializable data in you store, so i wont recommend this as a fix to the problem.
Adding onto @japalo solution, you can disable the serializationCheck specifically just for the oidc reducer by providing the options below:
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'
import { reducer as oidcReducer } from 'redux-oidc'
...
const store = configureStore(
{
reducer: {
YOUR_REDUCER(S)_HERE,
oidc: oidcReducer
}
middleware: [
...getDefaultMiddleware({
serializableCheck: {
ignoredActions: ['redux-oidc/USER_FOUND'],
ignoredPaths: ['oidc.user']
}
}),
...otherMiddlewares
],
devTools: process.env.NODE_ENV !== 'production' ? { CONFIG_GOES_HERE } : false
}
);
Documentation on these options for redux-toolkit can be found on the redux-toolkit docs.
Challenge
When we integrate the redux-oidc state into our project, we get the following error on all store calls:
The problem seems to be that the user object is a class
Our fix
We could fix that, by rewriting the following method inside
src/OidcProvider.js
:Parts of our code
This is how we make use of the reducer:
And this is the callback component