aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-frontend/src/slices/authorization.ts
blob: 5e9e8ca9a4d9e8666d5e7f1e8016715e787ce4e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { createSlice } from "@reduxjs/toolkit";

const authorizationSlice = createSlice({
    name: "authorization",
    initialState: {
        voucherToken: null as string | null,
        userToken: null as string | null,
        refreshTask: null as NodeJS.Timeout | null,
    },
    reducers: {
        setVoucherToken(state, action: { payload: string }) {
            state.voucherToken = action.payload;
        },
        setUserToken(state, action: { payload: string }) {
            state.userToken = action.payload;
        },
        clearToken(state) {
            state.voucherToken = null;
            state.userToken = null;
        },
        setRefreshTask(state, action: { payload: NodeJS.Timeout }) {
            state.refreshTask = action.payload;
        }
    },
});

export const { setVoucherToken, setUserToken, clearToken, setRefreshTask } = authorizationSlice.actions;

export default authorizationSlice.reducer;