Initial commit

This commit is contained in:
2026-04-02 09:23:57 +08:00
committed by GitHub
commit 8b3ccc6a51
36 changed files with 2887 additions and 0 deletions
+63
View File
@@ -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
+49
View File
@@ -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>()