AuctionHub Frontend is a highβperformance React + TypeScript singleβpage application (SPA) for a modern online auction experience.
It provides a seamless UI for browsing auctions, placing bids, managing your own listings, and performing admin operations.
This frontend application consumes the AuctionHub backend API built with ASP.NET Core.
Backend repository:
https://github.com/Qian1507/AuctionHub_backend
- Framework: React 18 (functional components & hooks)
- Language: TypeScript (strict typing)
- Build Tool: Vite (fast dev server & bundling)
- State Management: Context API (
AuthContext/AuthProvider) - Styling: Tailwind CSS (mobileβfirst responsive design)
- Networking: Axios with JWT interceptor
src/
βββ π api/
β βββ axiosInstance.ts # Axios instance with baseURL and request/response interceptors
βββ π¨ assets/
β βββ react.svg # Static assets (images, icons, etc.)
βββ π§± components/
β βββ π¨ auction/ # Auction-specific UI components
β β βββ AuctionBidHistory.tsx
β β βββ AuctionCard.tsx
β β βββ AuctionForm.tsx
β βββ Navbar.tsx # Global navigation bar
β βββ RequireAdmin.tsx # Route guard for admin-only access
β βββ UpdatePasswordForm.tsx# Reusable password update form
βββ π§ contexts/
β βββ AuthContext.ts # Authentication context definition
β βββ AuthProvider.tsx # Authentication state provider
β βββ useAuth.ts # Custom hook for accessing auth context
βββ π pages/
β βββ AdminDashboard.tsx # Admin management panel
β βββ AuctionCreate.tsx # Create new auction page
β βββ AuctionDetail.tsx # Auction item details view
β βββ AuctionEdit.tsx # Edit existing auction page
β βββ AuctionList.tsx # Main auction gallery/home page
β βββ Login.tsx # User login page
β βββ MyAuctions.tsx # User's personal auction management
β βββ Register.tsx # User registration page
β βββ UpdatePassword.tsx # Password management page
βββ π οΈ services/
β βββ auctionService.ts # Auction-related API service layer
β βββ authService.ts # Authentication & Authorization API calls
β βββ userService.ts # User profile & account management services
βββ π·οΈ types/
β βββ Types.ts # Global TypeScript interfaces and DTOs
βββ βοΈ utils/
β βββ errorUtils.ts # Centralized error handling logic
β βββ TokenHandler.ts # JWT storage and retrieval management
βββ π
App.css # Global styles and CSS variables
βββ π App.tsx # Root component & routing configuration
- Instant Onboarding: Automatic login immediately after a successful registration.
- Auction Tracking: "My Auctions" page with live status badges (
Live,Expired,Disabled). - Intuitive Feedback:
- Friendly empty states: "You haven't created any auctions yet."
- In-app password updates with real-time verification via
UpdatePasswordForm.
- Smart Validation: Server-side logic ensures all bids exceed the starting price/current highest bid and prevents self-bidding.
- Detailed Insights:
AuctionDetailpages feature full bid history, current high bid, and live status updates. - Unified Error Handling: Clear feedback for low bids or closed auctions using a centralized
getErrorMessageutility.
- Admin Hub: Dedicated dashboard (
AdminDashboard.tsx) for global auction oversight and management. - RBAC Protection: Granular route guarding using
<RequireAdmin>and<RequireAuth>. - Secure Access: Strictly enforces "Admin-only" or "Authenticated-only" access to sensitive routes.
- Desktop: High-density multi-column grids for auction cards and admin tables.
- Mobile: Fluid single-column layouts with stacked sections and adaptive navigation.
We use a modular service layer to keep the UI components clean and focused.
| Service | Responsibility | Key Methods |
|---|---|---|
auctionService |
Listing & Bidding | getAuctions, placeBid, createAuction |
authService |
Identity Management | login, register |
userService |
Profile Settings | updatePassword |
π View implementation details (Axios, JWT, Error Handling)
1οΈβ£ JWT HandlingUpon successful login, authService.login returns an object containing { token, user }. The AuthProvider then synchronizes this data with both React state and localStorage, ensuring persistence across sessions.
2οΈβ£ Global Axios Interceptor
A centralized axiosInstance (configured in TokenHandler.ts) automatically attaches the JWT token to all outgoing requests:
const axiosInstance = axios.create({ baseURL: import.meta.env.VITE_API_BASE_URL ?? "https://localhost:5001/api", });
axiosInstance.interceptors.request.use(config => {
const token = getToken();
if (token) {
config.headers.Authorization = Bearer ${token};
}
return config;
});
This ensures that all API calls are authenticated without requiring manual token handling in each request.
3οΈβ£ Error Handling & Normalization
The getErrorMessage utility extracts user-friendly error messages from Axios responses. It supports multiple response formats, including:
Plain string responses
Structured objects like { message: string }
This provides consistent and readable error handling across the application.
Follow these steps to run the project locally:
npm installCreate a .env file in the project root and add:
VITE_API_BASE_URL=https://localhost:5001/apiMake sure the backend is running and that the URL matches the API endpoint.
npm run devThe application will typically be available at:
http://localhost:5173
- API calls are organized in
services/andapi/axiosInstance.ts. - Authentication logic is centralized in
AuthContext/AuthProviderand accessed viauseAuth().
- Shared TypeScript interfaces in
types/Types.tsmatch backend DTOs. - This reduces bugs caused by mismatched data structures.
- Auction creation and editing share common logic and layout.
UpdatePasswordFormencapsulates the password change workflow and can be reused across different pages.
- Pages like MyAuctions clearly distinguish between:
- Loading
- Error
- Empty state ("no data")
- This provides immediate and clear feedback to users.
getErrorMessageconverts Axios errors into user-friendly messages.- Ensures consistent error display across the application.
- Protected routes (auth-only and admin-only) are handled via:
RequireAuthRequireAdmin
- These components read authentication state from
AuthContext.
This project is licensed under the MIT License.
Developed with β€οΈ by Qian Li

