Skip to content

Sencpc/React-project

Repository files navigation

React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

Authentication & Route Guards

  • 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 from localStorage, exposes login/logout, and normalises role-based redirects (shared constants live in src/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).
  • 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.

Project notes

  • The backend Express server lives in /server and now exposes Mongo-backed endpoints for authentication at POST /api/auth/register and POST /api/auth/login.
  • Configure the frontend to call the API by setting VITE_API_URL (defaults to http://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).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages