Instruction file imported from Adamj1232/summit-software-works (
.cursor/rules/routing-auth.mdc). Copyright stays with the author.
Routing & Authentication
- Library:
react-router-domv6 (checkpackage.jsonfor exact version) is used for routing. - Configuration: Routes are defined within
src/App.tsxusing<BrowserRouter>,<Routes>, and<Route>components. - Pages: Page components reside in
src/pages(e.g.,Index.tsx,Login.tsx,NotFound.tsx). - Authentication:
- Handled via
src/contexts/AuthContext.tsx(usinguseAuthhook). - A
ProtectedRoutecomponent (defined insrc/App.tsx) wraps routes that require authentication. - It checks the
isLoggedInstate fromAuthContextand redirects to/loginif the user is not authenticated.
- Handled via
- Adding Routes: When adding new pages/routes:
- Create the page component in
src/pages. - Add a new
<Route>entry insrc/App.tsx. - Wrap the route's
elementwith<ProtectedRoute>if it requires authentication.
- Create the page component in
- Context:
AuthProvidermust wrap the<Routes>insrc/App.tsxforuseAuthandProtectedRouteto function correctly.