feat: remove auth, store, redux, and axios from template

Agent-Logs-Url: https://github.com/zihluwang/delta-force-firearm-modification-codes/sessions/3477dccf-d002-4dda-ad39-4768da36bb9e

Co-authored-by: zihluwang <47817169+zihluwang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-02 01:27:56 +00:00
committed by GitHub
parent 5d44e24c95
commit b3caeb8ce5
7 changed files with 2 additions and 473 deletions
-40
View File
@@ -1,40 +0,0 @@
import { Navigate, Outlet, useLocation } from "react-router"
import { useAppSelector } from "@/store"
/**
* Renders child routes if the user is unauthenticated, otherwise redirects authenticated users to
* the root path.
*
* This component's logic allows unauthenticated users to access nested routes rendered
* via `Outlet`. Conversely, if a user is authenticated, they are redirected to the application's
* root path (`""`). This behaviour is inverse to the typical implementation of a 'protected route',
* which usually grants access to authenticated users and redirects unauthenticated users to a
* login page.
*/
export default function ProtectedRoute() {
/**
* Retrieves the authentication status from the Redux store.
*/
const isAuthenticated = useAppSelector((state) => state.auth.isAuthenticated)
/**
* Retrieves the current location object from React Router.
*/
const location = useLocation()
if (isAuthenticated) {
/**
* Redirects authenticated users to the application's root path (`""`).
*
* The redirection includes the current location's state, allowing the
* target route to know where the user was redirected from. The
* `replace` prop ensures the current history entry is replaced.
*/
return <Navigate to="" state={{ from: location }} replace />
}
/**
* Renders the child routes if the user is unauthenticated.
*/
return <Outlet />
}
+2 -9
View File
@@ -1,23 +1,16 @@
import { StrictMode } from "react"
import { createRoot } from "react-dom/client"
import { Provider as ReduxProvider } from "react-redux"
import { PersistGate } from "redux-persist/integration/react"
import { RouterProvider } from "react-router-dom"
import "@/init"
import store, { persistor } from "@/store"
import router from "@/router"
import "./index.css"
/**
* Main application entry point.
* Sets up the React app with Redux store and React Router.
* Sets up the React app with React Router.
*/
createRoot(document.getElementById("root")!).render(
<StrictMode>
<ReduxProvider store={store}>
<PersistGate persistor={persistor} loading={null}>
<RouterProvider router={router} />
</PersistGate>
</ReduxProvider>
<RouterProvider router={router} />
</StrictMode>,
)
-63
View File
@@ -1,63 +0,0 @@
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
@@ -1,49 +0,0 @@
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>()