Initial commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { createSlice } from "@reduxjs/toolkit"
|
||||
|
||||
/**
|
||||
* Defines the structure of the authentication state within the Redux store.
|
||||
*/
|
||||
interface AuthState {
|
||||
/**
|
||||
* Indicates whether a user is currently authenticated.
|
||||
* @type {boolean}
|
||||
*/
|
||||
isAuthenticated: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* The initial state for the authentication slice.
|
||||
*
|
||||
* By default, the user is considered unauthenticated.
|
||||
*
|
||||
* @constant
|
||||
* @type {AuthState}
|
||||
*/
|
||||
const initialState: AuthState = {
|
||||
isAuthenticated: false
|
||||
}
|
||||
|
||||
/**
|
||||
* A Redux Toolkit slice for managing authentication-related state.
|
||||
*
|
||||
* This slice includes the reducer, actions, and initial state for the authentication feature.
|
||||
* Currently, it only defines the initial state and no specific reducers, meaning it only
|
||||
* holds the `isAuthenticated` flag.
|
||||
*/
|
||||
const authSlice = createSlice({
|
||||
/**
|
||||
* The name of the slice, used to generate action types.
|
||||
* @type {string}
|
||||
*/
|
||||
name: "auth",
|
||||
/**
|
||||
* The initial state for this slice.
|
||||
* @type {AuthState}
|
||||
*/
|
||||
initialState,
|
||||
/**
|
||||
* An object of reducer functions. Currently empty, meaning no actions are explicitly defined for
|
||||
* state modification within this slice.
|
||||
* @type {object}
|
||||
*/
|
||||
reducers: {
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
// export const { } = authSlice.actions
|
||||
|
||||
/**
|
||||
* The reducer function for the authentication slice.
|
||||
*
|
||||
* This is the default export and should be combined with other reducers in the Redux store.
|
||||
*
|
||||
* @default
|
||||
*/
|
||||
export default authSlice.reducer
|
||||
@@ -0,0 +1,49 @@
|
||||
import { configureStore, combineReducers } from "@reduxjs/toolkit"
|
||||
import { useDispatch, useSelector } from "react-redux"
|
||||
import {
|
||||
persistStore,
|
||||
persistReducer,
|
||||
FLUSH,
|
||||
REHYDRATE,
|
||||
PAUSE,
|
||||
PERSIST,
|
||||
PURGE,
|
||||
REGISTER,
|
||||
} from "redux-persist"
|
||||
import createWebStorage from "redux-persist/es/storage/createWebStorage"
|
||||
import authReducer from "./auth-slice"
|
||||
|
||||
const storage = createWebStorage(import.meta.env.VITE_REDUX_STORAGE ?? "local")
|
||||
|
||||
const persistConfig = {
|
||||
key: "root",
|
||||
storage,
|
||||
whitelist: ["auth"],
|
||||
// blacklist: ['department'],
|
||||
}
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
auth: authReducer,
|
||||
})
|
||||
|
||||
const persistedReducer = persistReducer(persistConfig, rootReducer)
|
||||
|
||||
const store = configureStore({
|
||||
reducer: persistedReducer,
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware({
|
||||
serializableCheck: {
|
||||
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
export const persistor = persistStore(store)
|
||||
|
||||
export default store
|
||||
export type RootState = ReturnType<typeof rootReducer>
|
||||
export type AppDispatch = typeof store.dispatch
|
||||
export type AppStore = typeof store
|
||||
|
||||
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
|
||||
export const useAppSelector = useSelector.withTypes<RootState>()
|
||||
Reference in New Issue
Block a user