We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f92414f commit 044aebbCopy full SHA for 044aebb
1 file changed
client/src/redux/slice.js
@@ -1,5 +1,9 @@
1
import { createSlice } from "@reduxjs/toolkit";
2
3
+const isValidUser = (user) => {
4
+ return user && Object.keys(user).length > 0;
5
+};
6
+
7
export const userStateSlice = createSlice({
8
name: "userState",
9
initialState: {
@@ -10,7 +14,7 @@ export const userStateSlice = createSlice({
10
14
reducers: {
11
15
login: (state, action) => {
12
16
state.token = action.payload.token;
13
- state.user = action.payload.user;
17
+ state.user = isValidUser(action.payload.user) ? action.payload.user : null;
18
state.jwtExpiration = action.payload.jwtExpiration;
19
},
20
logout: (state) => {
0 commit comments