| Total Complexity | 4 |
| Complexity/F | 1 |
| Lines of Code | 38 |
| Function Count | 4 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | // src/redux/slices/authSlice.ts |
||
| 2 | import { createSlice } from '@reduxjs/toolkit'; |
||
| 3 | |||
| 4 | type AuthState = { |
||
| 5 | role: 'user' | 'admin' | 'guest'; |
||
| 6 | isLoggedIn: boolean, |
||
| 7 | token: string |
||
| 8 | user: string | null |
||
| 9 | }; |
||
| 10 | |||
| 11 | const initialState: AuthState = { |
||
| 12 | role: 'guest', |
||
| 13 | isLoggedIn: false, |
||
| 14 | token: '', |
||
| 15 | user: null |
||
| 16 | }; |
||
| 17 | |||
| 18 | const authSlice = createSlice({ |
||
| 19 | name: 'auth', |
||
| 20 | initialState, |
||
| 21 | reducers: { |
||
| 22 | setRole(state, action) { |
||
| 23 | state.role = action.payload; |
||
| 24 | }, |
||
| 25 | setCurrentUser(state, action) { |
||
| 26 | state.user = action.payload; |
||
| 27 | }, |
||
| 28 | setLoggedInOut(state, action) { |
||
| 29 | state.isLoggedIn = action.payload |
||
| 30 | }, |
||
| 31 | setToken(state, action) { |
||
| 32 | state.token = action.payload |
||
| 33 | } |
||
| 34 | }, |
||
| 35 | }); |
||
| 36 | |||
| 37 | export const { setRole, setCurrentUser, setLoggedInOut, setToken } = authSlice.actions; |
||
| 38 | export default authSlice.reducer; |