All files / src/store/slices/auth UserAuth.js

100% Statements 12/12
100% Branches 0/0
100% Functions 4/4
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 30 31 32 33 34 35 36 37 38 39 40 41 42 43                    5x                 1x 1x 1x     1x 1x 1x     1x 1x 1x       1x         5x    
/**
 * Auth0-based Auth Slice
 *
 * Auth0 SDK handles all authentication state (login, logout, tokens).
 * This slice only manages the user profile data for Redux consumers.
 *
 * Login/register thunks have been removed — Auth0 Universal Login handles those flows.
 */
import { createSlice } from "@reduxjs/toolkit";
 
const UserAuth = createSlice({
    name: "UserAuth",
    initialState: {
        userData: null,
        hasErrors: null,
        isLoading: false,
    },
    reducers: {
        setUser: (state, action) => {
            state.userData = action.payload;
            state.hasErrors = null;
            state.isLoading = false;
        },
        clearUser: (state) => {
            state.userData = null;
            state.hasErrors = null;
            state.isLoading = false;
        },
        _userLogout: (state) => {
            state.userData = null;
            localStorage.removeItem("role");
            localStorage.removeItem("access_token");
            // Auth0 logout is handled by the component calling useAuth0().logout()
        },
        _removeErrors: (state) => {
            state.hasErrors = null;
        },
    },
});
 
export const { setUser, clearUser, _userLogout, _removeErrors } = UserAuth.actions;
export default UserAuth;