Return user and Token instead of decoding token. Added transform to not store image in redux store

This commit is contained in:
Alex Holliday
2024-07-03 12:20:30 -07:00
parent 440716b021
commit f97aa1ca8c
4 changed files with 26 additions and 18 deletions
+2 -4
View File
@@ -67,10 +67,8 @@ const handleAuthFulfilled = (state, action) => {
state.isLoading = false;
state.success = action.payload.success;
state.msg = action.payload.msg;
state.authToken = action.payload.data;
const decodedToken = jwtDecode(action.payload.data);
const user = { ...decodedToken };
state.user = user;
state.authToken = action.payload.data.token;
state.user = action.payload.data.user;
};
const handleAuthRejected = (state, action) => {
state.isLoading = false;
+13 -1
View File
@@ -2,12 +2,24 @@ import { configureStore, combineReducers } from "@reduxjs/toolkit";
import monitorsReducer from "./Features/Monitors/monitorsSlice";
import authReducer from "./Features/Auth/authSlice";
import storage from "redux-persist/lib/storage";
import { persistReducer, persistStore } from "redux-persist";
import { persistReducer, persistStore, createTransform } from "redux-persist";
const authTransform = createTransform(
(inboundState) => {
const { profileImage, ...rest } = inboundState;
return rest;
},
// No transformation on rehydration
null,
// Only applies to auth
{ whitelist: ["auth"] }
);
const persistConfig = {
key: "root",
storage,
whitielist: ["auth", "monitors"],
transforms: [authTransform],
};
const rootReducer = combineReducers({