This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- @vitejs/plugin-react uses Babel (or oxc when used in rolldown-vite) for Fast Refresh
- @vitejs/plugin-react-swc uses SWC for Fast Refresh
- Set
VITE_API_URL
in your.env
(e.g.VITE_API_URL=http://localhost:4000
) so the frontend can reach the Express API. - The app boots inside an
AuthProvider
(src/context/AuthProvider.jsx
) which hydrates the logged-in user fromlocalStorage
, exposeslogin
/logout
, and normalises role-based redirects (shared constants live insrc/context/AuthContext.js
). ProtectedRoute
(src/Components/FrontEnd/Shared/ProtectedRoute.jsx
) works like middleware for React Router:- Unauthenticated visitors are redirected to
/login
and their original target is stored in router state. - Authenticated users hitting routes outside their role (e.g. customers on
/admin/*
) are redirected to their role home (/home
for customers,/admin/dashboard
for admins).
- Unauthenticated visitors are redirected to
- The login form consumes the context so successful authentication updates global state and navigation, while logging out (via future UI) will clear the stored token/user payload.
- The backend Express server lives in
/server
and now exposes Mongo-backed endpoints for authentication atPOST /api/auth/register
andPOST /api/auth/login
. - Configure the frontend to call the API by setting
VITE_API_URL
(defaults tohttp://localhost:4000
if not provided). - Authentication tokens are stored in
localStorage
by the login flow—ensure you protect these values appropriately in production (e.g., prefer HTTP-only cookies on a secure domain).