feat: hide statistics, work time, expenses and finances from regular users
This commit is contained in:
		@@ -1,10 +1,11 @@
 | 
			
		||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
 | 
			
		||||
import { jwtDecode, JwtPayload } from "jwt-decode";
 | 
			
		||||
import { jwtDecode, JwtPayload as JwtPayloadBase } from "jwt-decode";
 | 
			
		||||
 | 
			
		||||
interface AuthState {
 | 
			
		||||
    isAuthorized: boolean;
 | 
			
		||||
    accessToken: string;
 | 
			
		||||
    isGuest: boolean;
 | 
			
		||||
    role: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const initialState = (): AuthState => {
 | 
			
		||||
@@ -16,20 +17,26 @@ const initialState = (): AuthState => {
 | 
			
		||||
        accessToken: "",
 | 
			
		||||
        isAuthorized: false,
 | 
			
		||||
        isGuest: false,
 | 
			
		||||
        role: "user",
 | 
			
		||||
    };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
interface JwtPayload extends JwtPayloadBase {
 | 
			
		||||
    role: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const authSlice = createSlice({
 | 
			
		||||
    name: "auth",
 | 
			
		||||
    initialState,
 | 
			
		||||
    reducers: {
 | 
			
		||||
        login: (state, action: PayloadAction<{ accessToken: string }>) => {
 | 
			
		||||
            try {
 | 
			
		||||
                const { sub } = jwtDecode<JwtPayload>(
 | 
			
		||||
                    action.payload.accessToken
 | 
			
		||||
                const { sub, role } = jwtDecode<JwtPayload>(
 | 
			
		||||
                    action.payload.accessToken,
 | 
			
		||||
                );
 | 
			
		||||
                state.accessToken = action.payload.accessToken;
 | 
			
		||||
                state.isAuthorized = true;
 | 
			
		||||
                state.role = role;
 | 
			
		||||
                if (sub === "guest") state.isGuest = true;
 | 
			
		||||
            } catch (_) {
 | 
			
		||||
                const url = window.location.href;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user