frontend/src/redux/slices/authLogin.ts   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 38
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 4
mnd 0
bc 0
fnc 4
bpm 0
cpm 1
noi 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A authLogin.ts ➔ setToken 0 2 1
A authLogin.ts ➔ setRole 0 2 1
A authLogin.ts ➔ setLoggedInOut 0 2 1
A authLogin.ts ➔ setCurrentUser 0 2 1
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;