Revize 6129910f
Přidáno uživatelem Václav Honzík před asi 2 roky(ů)
frontend/src/features/Auth/userSlice.ts | ||
---|---|---|
8 | 8 |
refreshToken?: string |
9 | 9 |
username: string |
10 | 10 |
roles: string[] |
11 |
isLoggingIn: boolean |
|
11 | 12 |
isLoggedIn: boolean |
12 | 13 |
lastErr?: string // consumable for errors during thunks |
13 | 14 |
} |
... | ... | |
21 | 22 |
const initialState: UserState = { |
22 | 23 |
roles: [], |
23 | 24 |
isLoggedIn: false, |
25 |
isLoggingIn: false, |
|
24 | 26 |
username: '', |
25 | 27 |
} |
26 | 28 |
|
... | ... | |
41 | 43 |
...state, |
42 | 44 |
lastErr: action.payload, |
43 | 45 |
}), |
44 |
setUserState: (state, action) => { |
|
45 |
return ({ ...state, ...action.payload }) |
|
46 |
}, |
|
46 |
setUserState: (state, action) => ({ ...state, ...action.payload }), |
|
47 |
resetLoggingIn: (state) => ({ ...state, isLoggingIn: false }), |
|
47 | 48 |
}, |
48 | 49 |
|
49 | 50 |
// Thunks |
50 | 51 |
extraReducers: (builder) => { |
51 | 52 |
builder.addCase(logIn.fulfilled, (state, action) => { |
52 |
return ({ ...state, ...action.payload })
|
|
53 |
return { ...state, ...action.payload }
|
|
53 | 54 |
}) |
54 | 55 |
builder.addCase(logIn.rejected, (state, action) => { |
55 | 56 |
if (action.payload && typeof action.error.message === 'string') { |
56 |
return ({ ...state, lastErr: action.error.message })
|
|
57 |
return { ...state, lastErr: action.error.message }
|
|
57 | 58 |
} |
58 | 59 |
}) |
60 |
builder.addCase(logIn.pending, (state, action) => { |
|
61 |
return { ...state, isLoggingIn: true } |
|
62 |
}) |
|
59 | 63 |
}, |
60 | 64 |
}) |
61 | 65 |
|
62 |
|
|
63 | 66 |
const userReducer = persistReducer(persistConfig, userSlice.reducer) |
64 | 67 |
|
65 |
export const { logout, refreshTokens, setErr, setUserState } = userSlice.actions |
|
68 |
export const { logout, refreshTokens, setErr, setUserState, resetLoggingIn } = userSlice.actions
|
|
66 | 69 |
|
67 | 70 |
export default userReducer |
Také k dispozici: Unified diff
Show dialog in login page
re #9628