Skip to content

Commit 044aebb

Browse files
committed
Added validation to ensure user is not undefined in production
1 parent f92414f commit 044aebb

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

client/src/redux/slice.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { createSlice } from "@reduxjs/toolkit";
22

3+
const isValidUser = (user) => {
4+
return user && Object.keys(user).length > 0;
5+
};
6+
37
export const userStateSlice = createSlice({
48
name: "userState",
59
initialState: {
@@ -10,7 +14,7 @@ export const userStateSlice = createSlice({
1014
reducers: {
1115
login: (state, action) => {
1216
state.token = action.payload.token;
13-
state.user = action.payload.user;
17+
state.user = isValidUser(action.payload.user) ? action.payload.user : null;
1418
state.jwtExpiration = action.payload.jwtExpiration;
1519
},
1620
logout: (state) => {

0 commit comments

Comments
 (0)