Getting the 'No reducer provided for key "auth"' error, think it's to do with how I'm passing it to the store from the slice. Everything is working fine apart from the No reducer error. Should I use a rootReducer ? Looked through the documentation but just drawing a blank
the store.js
import { configureStore } from '@reduxjs/toolkit';
import alertReducer from '../features/alerts/alertSlice';
import authReducer from '../features/auth/authSlice';
export const store = configureStore({
reducer: {
alert: alertReducer,
auth: authReducer
},
});
the authslice.js
import { createSlice } from '@reduxjs/toolkit';
import api from '../../utils/api';
import { setAlert } from '../alerts/alertSlice';
const slice = createSlice({
name: 'auth',
initialState: {
token: localStorage.getItem('token'),
isAuthenticated: null,
loading: true,
user: null,
},
reducers: {
registerSuccess: (state, action) => {
const { payload } = action.payload;
state.push({
payload,
isAuthenticated: true,
loading: false,
});
},
registerFail: (state) => {
localStorage.removeItem('token');
state.token = null;
state.isAuthenticated = false;
state.loading = false;
state.user = null;
},
},
});
const { registerSuccess, registerFail } = slice.actions;
export default slice.reducer;
// Register User
export const register = (formData) => async (dispatch) => {
try {
const res = await api.post('/users', formData);
dispatch(registerSuccess(res.data));
} catch (err) {
const errors = err.response.data.errors;
if (errors) {
errors.forEach((error) => dispatch(setAlert(error.msg, 'danger')));
}
dispatch(registerFail());
}
};
No reducer error stack
No reducer provided for key "auth" vendors~main.chunk.js:36893:20
e http://localhost:3000/static/js/vendors~main.chunk.js:36893
warning http://localhost:3000/static/js/vendors~main.chunk.js:45798
combineReducers http://localhost:3000/static/js/vendors~main.chunk.js:45882
configureStore http://localhost:3000/static/js/vendors~main.chunk.js:1121
js http://localhost:3000/static/js/main.chunk.js:320
js http://localhost:3000/static/js/main.chunk.js:400
__webpack_require__ http://localhost:3000/static/js/bundle.js:852
fn http://localhost:3000/static/js/bundle.js:151
js http://localhost:3000/static/js/main.chunk.js:1965
js http://localhost:3000/static/js/main.chunk.js:2071
__webpack_require__ http://localhost:3000/static/js/bundle.js:852
fn http://localhost:3000/static/js/bundle.js:151
js http://localhost:3000/static/js/main.chunk.js:1194
js http://localhost:3000/static/js/main.chunk.js:1324
__webpack_require__ http://localhost:3000/static/js/bundle.js:852
fn http://localhost:3000/static/js/bundle.js:151
js http://localhost:3000/static/js/main.chunk.js:895
js http://localhost:3000/static/js/main.chunk.js:1177
__webpack_require__ http://localhost:3000/static/js/bundle.js:852
fn http://localhost:3000/static/js/bundle.js:151
js http://localhost:3000/static/js/main.chunk.js:137
js http://localhost:3000/static/js/main.chunk.js:297
__webpack_require__ http://localhost:3000/static/js/bundle.js:852
fn http://localhost:3000/static/js/bundle.js:151
js http://localhost:3000/static/js/main.chunk.js:1843
js http://localhost:3000/static/js/main.chunk.js:1950
__webpack_require__ http://localhost:3000/static/js/bundle.js:852
fn http://localhost:3000/static/js/bundle.js:151
1 http://localhost:3000/static/js/main.chunk.js:2085
__webpack_require__ http://localhost:3000/static/js/bundle.js:852
checkDeferredModules http://localhost:3000/static/js/bundle.js:46
webpackJsonpCallback http://localhost:3000/static/js/bundle.js:33
<anonymous> http://localhost:3000/static/js/main.chunk.js:1